<!DOCTYPE html>
<html prefix="og: http://ogp.me/ns# article: http://ogp.me/ns/article# " lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>introduction-to-julia | 绿萝间</title>
<link href="../assets/css/all-nocdn.css" rel="stylesheet" type="text/css">
<link href="../assets/css/ipython.min.css" rel="stylesheet" type="text/css">
<link href="../assets/css/nikola_ipython.css" rel="stylesheet" type="text/css">
<meta name="theme-color" content="#5670d4">
<meta name="generator" content="Nikola (getnikola.com)">
<link rel="alternate" type="application/rss+xml" title="RSS" href="../rss.xml">
<link rel="canonical" href="https://muxuezi.github.io/posts/introduction-to-julia.html">
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"] ],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
        processEscapes: true
    },
    displayAlign: 'center', // Change this to 'center' to center equations.
    "HTML-CSS": {
        styles: {'.MathJax_Display': {"margin": 0}}
    }
});
</script><!--[if lt IE 9]><script src="../assets/js/html5.js"></script><![endif]--><meta name="author" content="Tao Junjie">
<link rel="prev" href="kivy-ch7-flappy-bird-app.html" title="kivy-ch7-flappy-bird-app" type="text/html">
<link rel="next" href="python-network-scripting-pp4e.html" title="python-network-scripting-pp4e" type="text/html">
<meta property="og:site_name" content="绿萝间">
<meta property="og:title" content="introduction-to-julia">
<meta property="og:url" content="https://muxuezi.github.io/posts/introduction-to-julia.html">
<meta property="og:description" content="Introduction to Julia (slides show)¶








Let's start with a quick overview of the basic syntax, emphasising differences with Python.









Why Jula (slides show)



David P. Sanders
Department ">
<meta property="og:type" content="article">
<meta property="article:published_time" content="2015-06-24T13:44:21+08:00">
<meta property="article:tag" content="CHS">
<meta property="article:tag" content="ipython">
<meta property="article:tag" content="Other">
<meta property="article:tag" content="Python">
</head>
<body>
<a href="#content" class="sr-only sr-only-focusable">Skip to main content</a>

<!-- Menubar -->

<nav class="navbar navbar-inverse navbar-static-top"><div class="container">
<!-- This keeps the margins nice -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar" aria-controls="bs-navbar" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="https://muxuezi.github.io/">

                <span id="blog-title">绿萝间</span>
            </a>
        </div>
<!-- /.navbar-header -->
        <div class="collapse navbar-collapse" id="bs-navbar" aria-expanded="false">
            <ul class="nav navbar-nav">
<li>
<a href="../archive.html">Archive</a>
                </li>
<li>
<a href="../categories/">Tags</a>
                </li>
<li>
<a href="../rss.xml">RSS feed</a>

                
            </li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
    <a href="introduction-to-julia.ipynb" id="sourcelink">Source</a>
    </li>

                
            </ul>
</div>
<!-- /.navbar-collapse -->
    </div>
<!-- /.container -->
</nav><!-- End of Menubar --><div class="container" id="content" role="main">
    <div class="body-content">
        <!--Body content-->
        <div class="row">
            
            
<article class="post-text h-entry hentry postpage" itemscope="itemscope" itemtype="http://schema.org/Article"><header><h1 class="p-name entry-title" itemprop="headline name"><a href="#" class="u-url">introduction-to-julia</a></h1>

        <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn">
                    Tao Junjie
            </span></p>
            <p class="dateline"><a href="#" rel="bookmark"><time class="published dt-published" datetime="2015-06-24T13:44:21+08:00" itemprop="datePublished" title="2015-06-24 13:44">2015-06-24 13:44</time></a></p>
            
        <p class="sourceline"><a href="introduction-to-julia.ipynb" id="sourcelink">Source</a></p>

        </div>
        

    </header><div class="e-content entry-content" itemprop="articleBody text">
    <div tabindex="-1" id="notebook" class="border-box-sizing">
    <div class="container" id="notebook-container">

<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Introduction-to-Julia-(slides-show)">
<a href="../portfolio/Introduction%20to%20Julia.slides.html">Introduction to Julia (slides show)</a><a class="anchor-link" href="introduction-to-julia.html#Introduction-to-Julia-(slides-show)">¶</a>
</h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Let's start with a quick overview of the basic syntax, emphasising differences with Python.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><a href="../portfolio/Why%20Julia.slides.html">Why Jula (slides show)</a></p>
<!-- TEASER_END -->

<ul>
<li>David P. Sanders</li>
<li>Department of Physics, Faculty of Sciences</li>
<li>National University of Mexico (UNAM)</li>
<li>Twitter: @DavidPSanders</li>
<li>GitHub: dpsanders</li>
</ul>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Variables-and-arithmetic">
<a href="http://docs.julialang.org/en/release-0.3/manual/variables/">Variables</a> and arithmetic<a class="anchor-link" href="introduction-to-julia.html#Variables-and-arithmetic">¶</a>
</h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Numeric values in Julia work similarly to Python:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Variables in Julia are created as in Python, with a simple assignment operation; variable names can be <em>arbitrary unicode characters</em>. Many may be entered in LaTeX notation, using tab substitution: type <code>\alpha&lt;TAB&gt;</code>. There is also tab completion on partial names: <code>\alp&lt;TAB&gt;</code></p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [1]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="mi">3</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[1]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [2]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="mi">5</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[2]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>5</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [3]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">α</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span> <span class="n">ℵ</span> <span class="o">=</span> <span class="mi">10</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[3]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>10</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Functions use parentheses (round brackets, <code>()</code>) around the arguments being passed. <code>println</code> prints its arguments, followed by a new line. [<code>print</code> omits the new line.]</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [4]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">println</span><span class="p">(</span><span class="s2">"α = "</span><span class="p">,</span> <span class="n">α</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>α = 3
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Simple functions may be defined with a nice mathematical syntax; <code>*</code> is not needed in simple expressions:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [5]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">=</span> <span class="mi">2</span><span class="n">x</span><span class="o">^</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">3</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span>
<span class="n">g</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">-</span> <span class="p">(</span><span class="mi">2</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[5]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>g (generic function with 1 method)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [6]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">f</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[6]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>28</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [7]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">g</span><span class="p">(</span><span class="mf">3.5</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[7]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>0.0</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Variable-substitution">Variable substitution<a class="anchor-link" href="introduction-to-julia.html#Variable-substitution">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>The values of variables may be substituted into strings in a simple way using the <code>$</code> operator:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [8]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># Variable substitution with $:</span>
<span class="n">name</span> <span class="o">=</span> <span class="s2">"David"</span>
<span class="n">greeting</span> <span class="o">=</span> <span class="s2">"Hello, $name"</span>
<span class="n">println</span><span class="p">(</span><span class="n">greeting</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Hello, David
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>More complicated expressions are wrapped in parentheses:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [9]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">μ</span> <span class="o">=</span> <span class="mi">3</span>
<span class="n">println</span><span class="p">(</span><span class="s2">"The sine of $μ is $(sin(μ))"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>The sine of 3 is 0.1411200080598672
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Numerical-types">Numerical types<a class="anchor-link" href="introduction-to-julia.html#Numerical-types">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>There are numerical types with different precisions: typing <code>Float&lt;TAB&gt;</code> or <code>Int&lt;TAB&gt;</code> will provide a list. Currently, in arithmetic calculations types are promoted to the machine type. (This looks likely to change soon.)</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Machine integers!</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [10]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="mf">1e16</span><span class="p">)</span>
<span class="n">a</span> <span class="o">*</span> <span class="mi">10</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[10]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>100000000000000000</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [11]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="o">=</span> <span class="n">int8</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">int8</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="n">a</span> <span class="o">+</span> <span class="n">b</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[11]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [12]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span> <span class="c1"># ans is the last result</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[12]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Int8</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>These promotion rules are defined in <code>int.jl</code>.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Arbitrary-precision-arithmetic">Arbitrary-precision arithmetic<a class="anchor-link" href="introduction-to-julia.html#Arbitrary-precision-arithmetic">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Arbitrary-precision integers and floating points are available through the types <code>BigInt</code> and <code>BigFloat</code>. The function <code>big</code> converts a number into the corresponding <code>Big</code> type:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [13]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">big</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[13]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>10</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [14]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[14]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>BigInt (constructor with 10 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Note that, unlike in Python, integers <em>are not</em> automatically promoted to arbitrary-precision integers.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<hr>
<p><strong>Exercise</strong>: Calculate powers of 10 using standard integers and <code>BigInt</code>s</p>
<hr>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [15]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mi">10</span><span class="o">^</span><span class="mi">18</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[15]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1000000000000000000</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [16]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mi">10</span><span class="o">**</span><span class="mi">5</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
syntax: use "^" instead of "**"
while loading In[16], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [17]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mi">10</span><span class="o">^</span><span class="mi">19</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[17]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>-8446744073709551616</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [18]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">ten</span> <span class="o">=</span> <span class="n">big</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[18]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>10</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [19]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">ten</span><span class="o">^</span><span class="mi">109</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[19]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [20]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">i</span> <span class="o">=</span> <span class="n">int8</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[20]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>10</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [21]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">i</span> <span class="o">*</span> <span class="n">big</span><span class="p">(</span><span class="mi">11</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[21]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>110</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [22]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[22]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>BigInt (constructor with 10 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [23]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">typemax</span><span class="p">(</span><span class="n">Int64</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[23]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>9223372036854775807</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [24]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mi">2</span><span class="o">^</span><span class="mi">63</span><span class="o">-</span><span class="mi">1</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[24]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>9223372036854775807</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [25]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">typemin</span><span class="p">(</span><span class="n">Int64</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[25]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>-9223372036854775808</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [26]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">-</span><span class="mi">2</span><span class="o">^</span><span class="mi">63</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[26]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>-9223372036854775808</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Complex-numbers">Complex numbers<a class="anchor-link" href="introduction-to-julia.html#Complex-numbers">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Complex numbers are written using <code>im</code> for the imaginary part:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [27]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="o">=</span> <span class="mi">7</span>
<span class="n">c</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="mf">3.5</span><span class="n">im</span><span class="p">)</span> <span class="o">*</span> <span class="n">a</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[27]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>7.0 + 24.5im</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [28]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">c</span><span class="o">.</span><span class="n">im</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[28]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>24.5</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [29]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">c</span><span class="o">.</span><span class="n">re</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">im</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[29]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>(7.0,24.5)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [30]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">c</span> <span class="o">*</span> <span class="n">conj</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>  <span class="c1"># conj is a function that returns the conjugate of a complex number</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[30]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>649.25 + 0.0im</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>(Tuples behave similarly to Python.)</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Rational-numbers">Rational numbers<a class="anchor-link" href="introduction-to-julia.html#Rational-numbers">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Rational numbers are also built into Julia; they are created using the <code>//</code> operator:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [31]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mi">3</span><span class="o">//</span><span class="mi">4</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[31]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3//4</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [32]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[32]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Rational{Int64} (constructor with 1 method)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [33]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="p">(</span><span class="n">big</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">//</span><span class="mi">4</span><span class="p">)</span><span class="o">^</span><span class="mi">50</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[33]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>717897987691852588770249//1267650600228229401496703205376</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [34]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[34]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Rational{BigInt} (constructor with 1 method)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [35]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mi">3</span><span class="o">//</span><span class="mi">4</span> <span class="o">+</span> <span class="mi">5</span><span class="o">//</span><span class="mi">6</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[35]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>19//12</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Operators are a convenient way of writing functions:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [36]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">+</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[36]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>7</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [37]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">//</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[37]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3//4</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [38]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">//</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[38]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>// (generic function with 8 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>We see that <code>//</code> is a <em>function</em>, implemented as a series of <em>methods</em>. We can see what these methods are:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [39]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">methods</span><span class="p">(</span><span class="o">//</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[39]:</div>

<div class="output_html rendered_html output_subarea output_execute_result">
8 methods for generic function <b>//</b>:<ul>
<li> //(n::<b>Integer</b>,d::<b>Integer</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/rational.jl#L15" target="_blank">rational.jl:15</a>
</li>
<li> //(x::<b>Rational{T<:integer>,y::<b>Integer</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/rational.jl#L16" target="_blank">rational.jl:16</a><li> //(x::<b>Integer</b>,y::<b>Rational{T<:integer>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/rational.jl#L17" target="_blank">rational.jl:17</a><li> //(x::<b>Rational{T<:integer>,y::<b>Rational{T<:integer>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/rational.jl#L18" target="_blank">rational.jl:18</a><li> //(x::<b>Complex{T<:real>,y::<b>Real</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/rational.jl#L19" target="_blank">rational.jl:19</a><li> //(x::<b>Real</b>,y::<b>Complex{T<:real>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/rational.jl#L20" target="_blank">rational.jl:20</a><li> //(x::<b>Complex{T<:real>,y::<b>Complex{T<:real>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/rational.jl#L23" target="_blank">rational.jl:23</a><li> //(X::<b>AbstractArray{T,N}</b>,y::<b>Number</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/rational.jl#L28" target="_blank">rational.jl:28</a>
</li></:real></b></:real></b>
</li></:real></b>
</li></:real></b>
</li></:integer></b></:integer></b>
</li></:integer></b>
</li></:integer></b>
</li>
</ul>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [40]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mi">3</span> <span class="o">+</span> <span class="o">-</span><span class="mi">34</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[40]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>-31</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>The expression <code>n::Integer</code> is a <em>type annotation</em> that specifies that the method applies when its first argument is of type <code>Integer</code>.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Clicking on the file name takes us directly to the Julia standard library source code on GitHub where these functions are defined!</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id='Vectors:-an-"equivalent"-of-Python-lists-and-numpy-arrays'>Vectors: an "equivalent" of Python lists <em>and</em> <code>numpy</code> arrays<a class="anchor-link" href="introduction-to-julia.html#Vectors:-an-%22equivalent%22-of-Python-lists-and-numpy-arrays">¶</a>
</h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>To store several values "in one variable", we can try to imitate using a "list" as we would in Python:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [41]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[41]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Int64,1}:
 3
 4
 5</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [42]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">typeof</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[42]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Array{Int64,1}</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>In Julia these objects are called <code>Array</code>s. The curly braces indicate type parameters of the <code>Array</code> type. The first is the type of element contained in the <code>Array</code> (all must be of the same type) and the second the number of dimensions.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<hr>
<p><strong>Exercise</strong>: Try to create an array in this way with elements of different types. What happens?</p>
<p><strong>Exercise</strong>: What does the following syntax do?:  <code>l = {3, 4, 7.5}</code></p>
<hr>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [43]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mf">7.5</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[43]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Float64,1}:
 3.0
 4.0
 7.5</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [44]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="mf">3.</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[44]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Float64,1}:
 3.0
 4.0
 5.0</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [45]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="mf">3.</span><span class="p">,</span> <span class="s2">"a"</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[45]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2-element Array{Any,1}:
 3.0 
  "a"</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [46]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="mf">3.</span><span class="p">,</span> <span class="s1">'a'</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[46]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2-element Array{Float64,1}:
  3.0
 97.0</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [47]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">{</span><span class="mf">3.</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="s2">"hello"</span><span class="p">,</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]}</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[47]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>4-element Array{Any,1}:
 3.0     
 4       
  "hello"
  [3,4]  </pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Indexing">Indexing<a class="anchor-link" href="introduction-to-julia.html#Indexing">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>The indices of Julia arrays are numbered starting at 1, unlike Python (where they are numbered starting at 0).</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [48]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>  
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[48]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3.0</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>The syntax for ranges is similar to that for Python:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [49]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[49]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2-element Array{Any,1}:
 3.0
 4  </pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>However, the limits must be explicitly specified:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [50]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="n">end</span><span class="p">]</span>   <span class="c1"># Use `end` explicitly</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[50]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Any,1}:
 4       
  "hello"
  [3,4]  </pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [51]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="n">end</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[51]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Any,1}:
 3.0     
 4       
  "hello"</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [52]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
BoundsError()
while loading In[52], in expression starting on line 1

 in getindex_3B_2413 at /home/tj2/Documents/julia/usr/bin/../lib/julia/sys.so</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Julia <code>Arrays</code>, like Python lists, but unlike <code>numpy</code> arrays, are dynamic. However, the syntax is rather different from Python -- to add an element at the end of the list, we write</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [53]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">]</span>
<span class="n">l</span> <span class="o">+</span> <span class="n">l</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[53]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Int64,1}:
  6
  8
 10</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [54]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">names</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[54]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>0-element Array{Any,1}</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [55]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]</span>

<span class="n">push</span><span class="o">!(</span>l, <span class="m">7</span><span class="o">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[55]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>4-element Array{Int64,1}:
 3
 4
 5
 7</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [56]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">methods</span><span class="p">(</span><span class="n">sizehint</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[56]:</div>

<div class="output_html rendered_html output_subarea output_execute_result">
11 methods for generic function <b>sizehint</b>:<ul>
<li> sizehint(a::<b>Array{T,1}</b>,sz::<b>Integer</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/array.jl#L495" target="_blank">array.jl:495</a>
</li>
<li> sizehint(B::<b>BitArray{1}</b>,sz::<b>Integer</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/bitarray.jl#L514" target="_blank">bitarray.jl:514</a>
</li>
<li> sizehint(s::<b>IntSet</b>,top::<b>Integer</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/intset.jl#L18" target="_blank">intset.jl:18</a>
</li>
<li> sizehint(d::<b>Dict{K,V}</b>,newsz) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/dict.jl#L445" target="_blank">dict.jl:445</a>
</li>
<li> sizehint(s::<b>Set{T}</b>,newsz) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/set.jl#L29" target="_blank">set.jl:29</a>
</li>
<li> sizehint(d::<b>HashDict{K,V,O<:union>,newsz) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/hashdict.jl#L224" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/hashdict.jl:224</a><li> sizehint(::<b>OrderedDict{K,V}</b>,...) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/delegate.jl#L11" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/delegate.jl:11</a>
</li>
<li> sizehint(::<b>OrderedSet{T}</b>,...) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/delegate.jl#L11" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/delegate.jl:11</a>
</li>
<li> sizehint(::<b>DefaultDictBase{K,V,F,D<:associative>,...) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/delegate.jl#L11" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/delegate.jl:11</a><li> sizehint(::<b>DefaultDict{K,V,F}</b>,...) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/delegate.jl#L11" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/delegate.jl:11</a>
</li>
<li> sizehint(::<b>DefaultOrderedDict{K,V,F}</b>,...) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/delegate.jl#L11" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/delegate.jl:11</a>
</li></:associative></b>
</li></:union></b>
</li>
</ul>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [57]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">push</span><span class="err">!</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[57]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>push! (generic function with 22 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [58]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">methods</span><span class="p">(</span><span class="n">push</span><span class="o">!)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[58]:</div>

<div class="output_html rendered_html output_subarea output_execute_result">
22 methods for generic function <b>push!</b>:<ul>
<li> push!(a::<b>Array{Any,1}</b>,item) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/array.jl#L458" target="_blank">array.jl:458</a>
</li>
<li> push!<i>{T}</i>(a::<b>Array{T,1}</b>,item) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/array.jl#L451" target="_blank">array.jl:451</a>
</li>
<li> push!(B::<b>BitArray{1}</b>,item) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/bitarray.jl#L454" target="_blank">bitarray.jl:454</a>
</li>
<li> push!(s::<b>IntSet</b>,n::<b>Integer</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/intset.jl#L32" target="_blank">intset.jl:32</a>
</li>
<li> push!(::<b>EnvHash</b>,k::<b>String</b>,v) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/env.jl#L114" target="_blank">env.jl:114</a>
</li>
<li> push!(t::<b>Associative{K,V}</b>,key,v) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/dict.jl#L241" target="_blank">dict.jl:241</a>
</li>
<li> push!(s::<b>Set{T}</b>,x) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/set.jl#L18" target="_blank">set.jl:18</a>
</li>
<li> push!<i>{T}</i>(q::<b>Deque{T}</b>,x) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/deque.jl#L189" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/deque.jl:189</a>
</li>
<li> push!(s::<b>Stack{S}</b>,x) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/stack.jl#L16" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/stack.jl:16</a>
</li>
<li> push!<i>{T,V<:number>(ct::<b>Accumulator{T,V<:number>,r::<b>Accumulator{T,V2<:number>) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/accumulator.jl#L50" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/accumulator.jl:50</a><li> push!<i>{T,V<:number>(ct::<b>Accumulator{T,V<:number>,x::<b>T</b>,a::<b>V<:number>) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/accumulator.jl#L45" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/accumulator.jl:45</a><li> push!<i>{T,V<:number>(ct::<b>Accumulator{T,V<:number>,x::<b>T</b>,a::<b>V2<:number>) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/accumulator.jl#L46" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/accumulator.jl:46</a><li> push!<i>{T,V<:number>(ct::<b>Accumulator{T,V<:number>,x::<b>T</b>) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/accumulator.jl#L47" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/accumulator.jl:47</a><li> push!<i>{K,C}</i>(cc::<b>ClassifiedCollections{K,C}</b>,key::<b>K</b>,e) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/classifiedcollections.jl#L44" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/classifiedcollections.jl:44</a>
</li>
<li> push!(s::<b>IntDisjointSets</b>) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/disjoint_set.jl#L82" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/disjoint_set.jl:82</a>
</li>
<li> push!<i>{T}</i>(s::<b>DisjointSets{T}</b>,x::<b>T</b>) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/disjoint_set.jl#L127" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/disjoint_set.jl:127</a>
</li>
<li> push!<i>{T}</i>(h::<b>BinaryHeap{T,Comp}</b>,v::<b>T</b>) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/heaps/binary_heap.jl#L138" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/heaps/binary_heap.jl:138</a>
</li>
<li> push!<i>{T}</i>(h::<b>MutableBinaryHeap{T,Comp}</b>,v::<b>T</b>) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/heaps/mutable_binary_heap.jl#L201" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/heaps/mutable_binary_heap.jl:201</a>
</li>
<li> push!(s::<b>OrderedSet{T}</b>,x) at <a href="https://github.com/JuliaLang/DataStructures.jl/tree/b4aea82ce1cf165b96115f9271efd33776435fe0/src/orderedset.jl#L26" target="_blank">/home/tj2/.julia/v0.4/DataStructures/src/orderedset.jl:26</a>
</li>
<li> push!(A) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/abstractarray.jl#L1384" target="_blank">abstractarray.jl:1384</a>
</li>
<li> push!(A,a,b) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/abstractarray.jl#L1385" target="_blank">abstractarray.jl:1385</a>
</li>
<li> push!(A,a,b,c...) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/abstractarray.jl#L1386" target="_blank">abstractarray.jl:1386</a>
</li></:number></b></:number></i>
</li></:number></b></:number></b></:number></i>
</li></:number></b></:number></b></:number></i>
</li></:number></b></:number></b></:number></i>
</li>
</ul>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [60]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]</span>
<span class="n">push</span><span class="o">!(</span>l, <span class="m">12</span>.001<span class="o">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
InexactError()
while loading In[60], in expression starting on line 2

 in push! at array.jl:451</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [61]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="mf">3.0</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]</span>
<span class="n">push</span><span class="o">!(</span>l, <span class="m">12</span>.001<span class="o">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[61]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>4-element Array{Float64,1}:
  3.0  
  4.0  
  5.0  
 12.001</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [62]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mf">12.0</span> <span class="o">==</span> <span class="mi">12</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[62]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>true</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [63]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">push</span><span class="o">!(</span>l, <span class="m">12</span>.1<span class="o">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[63]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>5-element Array{Float64,1}:
  3.0  
  4.0  
  5.0  
 12.001
 12.1  </pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [64]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">12</span><span class="p">]</span>
<span class="n">append</span><span class="o">!(</span>l, <span class="o">[</span><span class="m">10</span>., <span class="m">11</span>., <span class="m">12</span><span class="o">])</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[64]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>7-element Array{Int64,1}:
  3
  4
  5
 12
 10
 11
 12</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><code>push!</code> replaces <code>append</code> in Python. There are no methods of objects as in Python; rather, we use functions and send the object as an argument of the function.</p>
<p>The exclamation mark, or <em>bang</em>, (<code>!</code>) indicates that the function modifies its argument; this is a standard convention in Julia.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Arrays which have been defined with a certain type <em>cannot</em> acquire elements of a different type:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [65]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]</span>
<span class="n">push</span><span class="o">!(</span>l, <span class="s2">"hello"</span><span class="o">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
`convert` has no method matching convert(::Type{Int64}, ::ASCIIString)
while loading In[65], in expression starting on line 2

 in push! at array.jl:451</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><code>Array</code>s work as mathematical vectors, with the sum of two vectors and scalar multiplication being defined:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [66]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1.1</span><span class="p">,</span> <span class="mf">2.2</span><span class="p">,</span> <span class="mf">3.3</span><span class="p">]</span>
<span class="n">b</span> <span class="o">=</span> <span class="p">[</span><span class="mf">4.4</span><span class="p">,</span> <span class="mf">5.5</span><span class="p">,</span> <span class="mf">6.6</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[66]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Float64,1}:
 4.4
 5.5
 6.6</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [67]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="o">+</span> <span class="n">b</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[67]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Float64,1}:
 5.5
 7.7
 9.9</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [68]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mf">3.5</span> <span class="o">*</span> <span class="n">a</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[68]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Float64,1}:
  3.85
  7.7 
 11.55</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>However, operators are, in general, <em>not</em> treated in an elementwise fashion (as they would be e.g. in <code>numpy</code>):</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [69]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="o">*</span> <span class="n">b</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
`*` has no method matching *(::Array{Float64,1}, ::Array{Float64,1})
while loading In[69], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Rather, elementwise operations use a Matlab-like syntax, with an extra <code>.</code> before the symbol for the operator:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [70]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="o">.*</span> <span class="n">b</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[70]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Float64,1}:
  4.84
 12.1 
 21.78</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>There are many useful operations on vectors predefined, without needing to explicitly import them.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [71]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">dot</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[71]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>38.72</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [72]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>dot
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>dot (generic function with 7 methods)
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [73]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">cross</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[73]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Float64,1}:
 -3.63
  7.26
 -3.63</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [74]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>cross
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>cross (generic function with 1 method)
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [75]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">norm</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[75]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>4.115823125451335</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [76]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>norm
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.norm(A[, p])

   Compute the "p"-norm of a vector or the operator norm of a matrix
   "A", defaulting to the "p=2"-norm.

   For vectors, "p" can assume any numeric value (even though not
   all values produce a mathematically valid vector norm). In
   particular, "norm(A, Inf)" returns the largest value in
   "abs(A)", whereas "norm(A, -Inf)" returns the smallest.

   For matrices, valid values of "p" are "1", "2", or "Inf".
   (Note that for sparse matrices, "p=2" is currently not
   implemented.) Use "vecnorm()" to compute the Frobenius norm.
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Use <code>help</code> or <code>?</code> (before the command) to obtain help:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [77]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">help</span><span class="p">(</span><span class="n">dot</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>dot (generic function with 7 methods)
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [78]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>dot
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>dot (generic function with 7 methods)
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [79]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">transpose</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[79]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1x3 Array{Float64,2}:
 1.1  2.2  3.3</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [80]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span><span class="s1">'</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[80]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1x3 Array{Float64,2}:
 1.1  2.2  3.3</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [81]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">transpose</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="o">==</span> <span class="n">a</span><span class="s1">'</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[81]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>true</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [82]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">2</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">]]</span> <span class="c1"># 1-d</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[82]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>4-element Array{Int64,1}:
 2
 1
 1
 1</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [83]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">push</span><span class="o">!(</span>l, <span class="m">12</span>.0<span class="o">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[83]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>4-element Array{Int64,1}:
  3
  4
  5
 12</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [84]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.</span> <span class="mi">1</span><span class="p">;</span> <span class="mi">1</span> <span class="mi">1</span><span class="p">]</span> <span class="c1"># 2-d</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[84]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2x2 Array{Float64,2}:
 2.0  1.0
 1.0  1.0</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [85]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">([</span><span class="mi">1</span><span class="p">:</span><span class="mi">8</span><span class="p">],</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[85]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2x2x2 Array{Int64,3}:
[:, :, 1] =
 1  3
 2  4

[:, :, 2] =
 5  7
 6  8</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [86]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="err">⋅</span> <span class="n">b</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[86]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>38.72</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [87]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">dot</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">)</span> <span class="o">==</span> <span class="n">a</span> <span class="err">⋅</span> <span class="n">b</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[87]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>true</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [88]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="err">×</span> <span class="n">b</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[88]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Float64,1}:
 -3.63
  7.26
 -3.63</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [89]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">cross</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">)</span> <span class="o">==</span> <span class="n">a</span> <span class="err">×</span> <span class="n">b</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[89]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>true</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>I used <code>\cdot</code></p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [90]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="err">⋅</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[90]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>dot (generic function with 7 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>[Note that in the Julia command-line REPL, typing <code>?</code> puts it immediately into a special help mode. Similarly, <code>;</code> puts it into shell mode, in which commands are sent straight to the shell.]</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Control-flow:-drop-the-colon-(:)-and-add-end">Control flow: drop the colon (<code>:</code>) and add <code>end</code><a class="anchor-link" href="introduction-to-julia.html#Control-flow:-drop-the-colon-(:)-and-add-end">¶</a>
</h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>White space in Julia is <em>not</em> significant. Commands on one line can be separated by <code>;</code>. Blocks <em>must</em> finish with <code>end</code></p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [91]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">while</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="mi">5</span> 
    <span class="nb">print</span><span class="p">(</span><span class="s2">"$i</span><span class="se">\t</span><span class="s2">"</span><span class="p">)</span>
    <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">end</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>0	1	2	3	4	</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [92]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">total</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">:</span><span class="mi">26</span>
    <span class="n">total</span> <span class="o">+=</span> <span class="mi">2</span><span class="o">^</span><span class="n">i</span>
<span class="n">end</span>
<span class="n">println</span><span class="p">(</span><span class="s2">"Sum is $total"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Sum is 134217726
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Here, <code>1:26</code> is a <em>range object</em> which may be iterated over.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [93]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">typeof</span><span class="p">(</span><span class="mi">1</span><span class="p">:</span><span class="mi">10</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[93]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>UnitRange{Int64} (constructor with 1 method)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>We can construct an array from this by enclosing it in square brackets:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [94]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">collect</span><span class="p">(</span><span class="mi">1</span><span class="p">:</span><span class="mi">10</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[94]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>10-element Array{Int64,1}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [95]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>collect
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.collect(collection)

   Return an array of all items in a collection. For associative
   collections, returns (key, value) tuples.

Base.collect(element_type, collection)

   Return an array of type "Array{element_type,1}" of all items in a
   collection.
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [96]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">:</span><span class="mi">10</span><span class="p">,</span> <span class="mi">17</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[96]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>6-element Array{Int64,1}:
  1
  3
  5
  7
  9
 17</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [97]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">help</span><span class="p">(</span><span class="s2">"dot"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.LinAlg.BLAS.dot(n, X, incx, Y, incy)

   Dot product of two vectors consisting of "n" elements of array
   "X" with stride "incx" and "n" elements of array "Y" with
   stride "incy".
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><strong>Exercise</strong>: Implement the Babylonian method for calculating the square root of a positive number $y$, via the iteration 
$$x_{n+1} = \textstyle \frac{1}{2} (x_n + \frac{y}{x_n})$$</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [98]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="mi">7</span>
<span class="c1"># Babylonian method</span>
<span class="n">r1</span> <span class="o">=</span> <span class="n">big</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">:</span><span class="mi">10</span>
    <span class="n">r2</span> <span class="o">=</span> <span class="p">(</span><span class="n">r1</span><span class="o">+</span><span class="n">x</span><span class="o">//</span><span class="n">r1</span><span class="p">)</span><span class="o">//</span><span class="mi">2</span>
    <span class="n">r1</span> <span class="o">=</span> <span class="n">r2</span>
    <span class="n">println</span><span class="p">(</span><span class="s2">"$i: $r2 is $(float(r2))"</span><span class="p">)</span>
<span class="n">end</span>
<span class="n">sqrt</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>1: 4//1 is 4e+00
2: 23//8 is 2.875e+00
3: 977//368 is 2.654891304347826086956521739130434782608695652173913043478260869565217391304333e+00
4: 1902497//719072 is 2.645767044190289706733122691469004494682034622402207289395220506430510435672636e+00
5: 7238946623297//2736064645568 is 2.645751311111369320474788060415261270876928274529823742547961659814056687694087e+00
6: 104804696428033056657448577//39612451854313553433195392 is 2.645751311064590590502029293938515493859933284910652657274139597282698886360655e+00
7: 21968048786744329890159858491687242656637852949560577//8303141982722814210287293056980408998691454066714368 is 2.645751311064590590501615753639260425710259215401356797324429072042618334785781e+00
8: 965190334993558048952747224707737662553546023969581717336893753948305178090306054973804711697153676048897//364807656319439656893574197813762741889129729119092813240115363343939412817707718620985339231655544540672 is 2.645751311064590590501615753639260425710259183082450180368334459201068823230298e+00
9: 1863184765529953614442676969410516768705348877426018592874619682164981370927579559773987864606096009580887559742891544147556039040815814753743851100010309178655530447444083262328821461724034060383304637370397697//704217648022349512771442189018194725339511495157190929516136319260161990261007461575776992568187313708188185637682782310132281240170939460318854442124039911242297405920199037531309472261446561026954943354477568 is 2.645751311064590590501615753639260425710259183082450180368334459201068823230264e+00
10: 6942914941005816452906820447809898528401948252945007180207641686978710969653763380353810662539739407094605662843293836754945636431635508103618963852112274901648239421682834044604657380796983687411621541616911160282084512012755071820846262756649514791264502834906610162581301591431279046989968494539999498942229056113659738389773073293970820133886115413882850641756087247746883347629340780021440048884451568277591449266177//2624175186825153359249378049906502688043810272014845844292434248994264560667710669982033339453245573538963306071655131184848403463172113026723021373675261241203122087530398269881154662495920113030441863771241633914463530742637259717641425928569498576675875622441689707127692085122998906191651056070668909263006767739390431278990942834266700554990212884068483635241604906439758589382529929519521217527464936293523650721792 is 2.645751311064590590501615753639260425710259183082450180368334459201068823230264e+00
</pre>
</div>
</div>

<div class="output_area">
<div class="prompt output_prompt">Out[98]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2.6457513110645907</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [99]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="err">♆</span> <span class="o">=</span> <span class="n">norm</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[99]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>norm (generic function with 15 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [100]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="err">♆</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[100]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>4.115823125451335</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [101]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">snowman</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">=</span> <span class="n">x</span><span class="o">^</span><span class="mi">3</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[101]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>snowman (generic function with 1 method)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [102]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="err">☃</span> <span class="o">=</span> <span class="n">snowman</span>
<span class="err">☃</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[102]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>27</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Short-circuit-evaluation">Short-circuit evaluation<a class="anchor-link" href="introduction-to-julia.html#Short-circuit-evaluation">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [103]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="o">=</span> <span class="mi">3</span>
<span class="n">a</span> <span class="o">&lt;</span> <span class="mi">5</span> <span class="o">&amp;&amp;</span> <span class="n">println</span><span class="p">(</span><span class="s2">"Small"</span><span class="p">)</span>   <span class="c1"># evaluate the second statement only if the first is true;  semantics of if-then</span>

<span class="n">a</span> <span class="o">&gt;</span> <span class="mi">10</span> <span class="o">||</span> <span class="n">println</span><span class="p">(</span><span class="s2">"Small"</span><span class="p">)</span>  <span class="c1"># semantics of if not-then</span>

<span class="c1"># equal to</span>

<span class="k">if</span> <span class="n">a</span> <span class="o">&lt;</span> <span class="mi">5</span>
    <span class="n">println</span><span class="p">(</span><span class="s2">"small, if-then"</span><span class="p">)</span>
<span class="n">end</span>

<span class="k">if</span> <span class="n">a</span> <span class="o">&gt;</span> <span class="mi">10</span>
    <span class="n">println</span><span class="p">(</span><span class="s2">"small, if not-then"</span><span class="p">)</span>
<span class="n">end</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Small
Small
small, if-then
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [104]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="o">==</span> <span class="mi">3</span> <span class="err">?</span> <span class="n">println</span><span class="p">(</span><span class="s2">"Hello"</span><span class="p">)</span> <span class="p">:</span> <span class="n">println</span><span class="p">(</span><span class="s2">"Not true"</span><span class="p">)</span>

<span class="c1"># equal to</span>

<span class="k">if</span> <span class="n">a</span> <span class="o">&lt;</span> <span class="mi">5</span>
    <span class="n">println</span><span class="p">(</span><span class="s2">"small, if-then"</span><span class="p">)</span>
<span class="k">else</span>
    <span class="n">println</span><span class="p">(</span><span class="s2">"small, if not-then"</span><span class="p">)</span>
<span class="n">end</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Hello
small, if-then
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Array-comprehensions">Array comprehensions<a class="anchor-link" href="introduction-to-julia.html#Array-comprehensions">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>There is an equivalent of list comprehensions in Python, as follows. Note that the array construction syntax is quite flexible.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [105]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">squares</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span><span class="o">^</span><span class="mi">2</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">:</span><span class="mi">10</span><span class="p">,</span> <span class="mi">7</span><span class="p">]]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[105]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>6-element Array{Any,1}:
  1
  9
 25
 49
 81
 49</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [106]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">sums</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span> <span class="k">for</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">:</span><span class="mi">5</span><span class="p">,</span> <span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span> <span class="c1"># boardcasting</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[106]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>5x5 Array{Int64,2}:
 2  3  4  5   6
 3  4  5  6   7
 4  5  6  7   8
 5  6  7  8   9
 6  7  8  9  10</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [107]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">sums</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="o">+</span><span class="n">k</span> <span class="k">for</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">:</span><span class="mi">5</span><span class="p">,</span> <span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">:</span><span class="mi">5</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="mi">1</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[107]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>5x5x5 Array{Int64,3}:
[:, :, 1] =
 3  4  5   6   7
 4  5  6   7   8
 5  6  7   8   9
 6  7  8   9  10
 7  8  9  10  11

[:, :, 2] =
 4  5   6   7   8
 5  6   7   8   9
 6  7   8   9  10
 7  8   9  10  11
 8  9  10  11  12

[:, :, 3] =
 5   6   7   8   9
 6   7   8   9  10
 7   8   9  10  11
 8   9  10  11  12
 9  10  11  12  13

[:, :, 4] =
  6   7   8   9  10
  7   8   9  10  11
  8   9  10  11  12
  9  10  11  12  13
 10  11  12  13  14

[:, :, 5] =
  7   8   9  10  11
  8   9  10  11  12
  9  10  11  12  13
 10  11  12  13  14
 11  12  13  14  15</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Matrices">Matrices<a class="anchor-link" href="introduction-to-julia.html#Matrices">¶</a>
</h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Square brackets with commas gives a one-dimensional vector. This is printed in a way that treats it as if it were a column vector (although there is in fact no difference between a <em>one-dimensional</em> row vector and column vector).</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [108]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[108]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3-element Array{Int64,1}:
 3
 4
 5</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>To create explicit matrices, Matlab-style notation is used. If we omit the commas, something different happens: we now obtain a <em>two-dimensional</em> <code>Array</code>, i.e. a matrix, of size $1 \times n$. [Recall that in the standard notation for matrices, an $m \times n$ matrix has $m$ <em>rows</em> and $n$ <em>columns</em>.]</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [109]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">row_vec</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span> <span class="mi">4</span> <span class="mi">5</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[109]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1x3 Array{Int64,2}:
 3  4  5</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [110]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span> <span class="o">==</span> <span class="n">row_vec</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[110]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>false</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>We can also use the transpose operator, <code>'</code>. [This is actually the <em>conjugate</em>-transpose operator, which also takes the complex conjugate of complex numbers. Transpose without conjugate is denoted <code>.'</code>]</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [111]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">row_vec</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="n">im</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span><span class="s1">'</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[111]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1x2 Array{Complex{Int64},2}:
 0-2im  2+0im</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [112]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">row_vec</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="n">im</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="s1">'</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[112]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1x2 Array{Complex{Int64},2}:
 0+2im  2+0im</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>A complete matrix may be constructed using a semicolon (<code>;</code>) to separate rows:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [113]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span> <span class="mi">2</span><span class="n">im</span><span class="p">;</span> <span class="mi">3</span> <span class="mi">4</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[113]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2x2 Array{Complex{Int64},2}:
 1+0im  0+2im
 3+0im  4+0im</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>As in <code>numpy</code>, it may also be created using a <code>reshape</code>:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [114]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">([</span><span class="mi">1</span> <span class="mi">2</span> <span class="mi">3</span> <span class="mi">4</span><span class="p">],</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>

<span class="c1"># equal to</span>

<span class="n">N</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[114]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2x2 Array{Int64,2}:
 1  3
 2  4</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [115]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span> <span class="o">==</span> <span class="n">N</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[115]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>true</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Here, as in Python, <code>(2,2)</code> denotes an (immutable) tuple:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [116]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">t</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">typeof</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[116]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>(Int64,Int64)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>There is an important difference in the way that Python and Julia treat slices of matrices. While in Python a one-dimensional slice in either direction returns a 1-dimensional vector, in Julia there is a difference. A vertical one-dimensional slice gives a 1-dimensional vector (a "column vector"):</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [117]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[117]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2-element Array{Int64,1}:
 1
 2</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>However, a horizontal one-dimensional slice produces a $1 \times n$ matrix:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [118]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span><span class="p">[</span><span class="mi">1</span><span class="p">,:]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[118]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1x2 Array{Int64,2}:
 1  3</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>This is the same result that is produced using the following Matlab-like syntax:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [119]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="p">[</span><span class="mi">1</span> <span class="mi">2</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[119]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1x2 Array{Int64,2}:
 1  2</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Random-numbers">Random numbers<a class="anchor-link" href="introduction-to-julia.html#Random-numbers">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>The Mersenne Twister (pseudo-)random number generator is built-in to Julia:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [120]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">rand</span><span class="p">()</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[120]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>0.40186768641976944</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [121]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">rand</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[121]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>5-element Array{Float64,1}:
 0.344519
 0.617192
 0.829609
 0.981215
 0.477052</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [122]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">rand</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[122]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>5x5 Array{Float64,2}:
 0.634627  0.121441   0.793247  0.78431   0.965882
 0.989307  0.616908   0.353485  0.710715  0.635409
 0.352762  0.118025   0.185011  0.280691  0.28924 
 0.748569  0.195795   0.279713  0.831955  0.888495
 0.765     0.0837347  0.537341  0.429161  0.147381</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [123]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="n">rand</span><span class="p">(</span><span class="n">Int32</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[123]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3x3 Array{Int32,2}:
  -113324951   196613133  -1363228423
 -2088630349  1597727404   -358295295
 -1080816523  1898363541    571418313</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [124]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>rand
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.rand() -&gt; Float64

   Generate a "Float64" random number uniformly in [0,1)

Base.rand(rng::AbstractRNG[, dims...])

   Generate a random "Float64" number or array of the size specified
   by dims, using the specified RNG object. Currently,
   "MersenneTwister" is the only available Random Number Generator
   (RNG), which may be seeded using srand.

Base.rand(dims or [dims...])

   Generate a random "Float64" array of the size specified by dims

Base.rand(t::Type[, dims...])

   Generate a random number or array of random numbes of the given
   type.

Base.rand(r[, dims...])

   Pick a random element or array of random elements from range "r"
   (for example, "1:n" or "0:2:10").
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [125]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">methods</span><span class="p">(</span><span class="n">rand</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[125]:</div>

<div class="output_html rendered_html output_subarea output_execute_result">
33 methods for generic function <b>rand</b>:<ul>
<li> rand(::<b>Type{Float64}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L91" target="_blank">random.jl:91</a>
</li>
<li> rand() at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L92" target="_blank">random.jl:92</a>
</li>
<li> rand(::<b>Type{Float32}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L94" target="_blank">random.jl:94</a>
</li>
<li> rand(::<b>Type{Float16}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L95" target="_blank">random.jl:95</a>
</li>
<li> rand<i>{T<:real>(::<b>Type{Complex{T<:real>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L97" target="_blank">random.jl:97</a><li> rand(r::<b>MersenneTwister</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L100" target="_blank">random.jl:100</a>
</li>
<li> rand(::<b>Type{Uint8}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L107" target="_blank">random.jl:107</a>
</li>
<li> rand(::<b>Type{Uint16}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L108" target="_blank">random.jl:108</a>
</li>
<li> rand(::<b>Type{Uint32}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L109" target="_blank">random.jl:109</a>
</li>
<li> rand(::<b>Type{Uint64}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L110" target="_blank">random.jl:110</a>
</li>
<li> rand(::<b>Type{Uint128}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L111" target="_blank">random.jl:111</a>
</li>
<li> rand(::<b>Type{Int8}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L113" target="_blank">random.jl:113</a>
</li>
<li> rand(::<b>Type{Int16}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L114" target="_blank">random.jl:114</a>
</li>
<li> rand(::<b>Type{Int32}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L115" target="_blank">random.jl:115</a>
</li>
<li> rand(::<b>Type{Int64}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L116" target="_blank">random.jl:116</a>
</li>
<li> rand(::<b>Type{Int128}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L117" target="_blank">random.jl:117</a>
</li>
<li> rand(::<b>Type{Float64}</b>,dims::<b>(Int64...,)</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L121" target="_blank">random.jl:121</a>
</li>
<li> rand(::<b>Type{Float64}</b>,dims::<b>Int64...</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L122" target="_blank">random.jl:122</a>
</li>
<li> rand(dims::<b>(Int64...,)</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L124" target="_blank">random.jl:124</a>
</li>
<li> rand(dims::<b>Int64...</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L125" target="_blank">random.jl:125</a>
</li>
<li> rand(r::<b>AbstractRNG</b>,dims::<b>(Int64...,)</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L127" target="_blank">random.jl:127</a>
</li>
<li> rand(r::<b>AbstractRNG</b>,dims::<b>Int64...</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L128" target="_blank">random.jl:128</a>
</li>
<li> rand(::<b>Type{Bool}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L244" target="_blank">random.jl:244</a>
</li>
<li> rand<i>{T<:number>(::<b>Type{T<:number>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L145" target="_blank">random.jl:145</a><li> rand(T::<b>Type{T<:top>,dims::<b>(Int64...,)</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L144" target="_blank">random.jl:144</a><li> rand<i>{T<:number>(::<b>Type{T<:number>,dims::<b>Int64...</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L146" target="_blank">random.jl:146</a><li> rand<i>{T<:union>(g::<b>RandIntGen{T<:union>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L189" target="_blank">random.jl:189</a><li> rand<i>{T<:integer>(g::<b>RandIntGen{T<:integer>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L205" target="_blank">random.jl:205</a><li> rand<i>{T<:union>(r::<b>UnitRange{T<:union>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L212" target="_blank">random.jl:212</a><li> rand<i>{T}</i>(r::<b>Range{T}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L213" target="_blank">random.jl:213</a>
</li>
<li> rand<i>{T}</i>(r::<b>Range{T}</b>,dims::<b>(Int64...,)</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L232" target="_blank">random.jl:232</a>
</li>
<li> rand(r::<b>Range{T}</b>,dims::<b>Int64...</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L233" target="_blank">random.jl:233</a>
</li>
<li> rand(state::<b>DSFMT_state</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/random.jl#L739" target="_blank">random.jl:739</a>
</li></:union></b></:union></i>
</li></:integer></b></:integer></i>
</li></:union></b></:union></i>
</li></:number></b></:number></i>
</li></:top></b>
</li></:number></b></:number></i>
</li></:real></b></:real></i>
</li>
</ul>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Matrix-multiplication">Matrix multiplication<a class="anchor-link" href="introduction-to-julia.html#Matrix-multiplication">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [126]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[126]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2-element Array{Int64,1}:
 1
 2</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [127]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span><span class="o">*</span><span class="n">v</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
`*` has no method matching *(::Array{Int64,1}, ::Array{Int64,1})
while loading In[127], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [128]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span><span class="o">^</span><span class="mi">2</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
`*` has no method matching *(::Array{Int64,1}, ::Array{Int64,1})
while loading In[128], in expression starting on line 1

 in power_by_squaring at intfuncs.jl:56
 in ^ at intfuncs.jl:86</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [129]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">dot</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[129]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>5</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [130]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span> <span class="mi">1</span><span class="p">;</span> <span class="mi">1</span> <span class="mi">1</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[130]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2x2 Array{Int64,2}:
 2  1
 1  1</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [131]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">dot</span><span class="p">(</span><span class="n">M</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
`dot` has no method matching dot(::Array{Int64,2}, ::Array{Int64,1})
while loading In[131], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Matrix multiplication uses the <code>*</code> operator:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [132]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span> <span class="o">*</span> <span class="n">v</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[132]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2-element Array{Int64,1}:
 4
 3</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [133]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nd">@which</span> <span class="n">M</span><span class="o">*</span><span class="n">v</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[133]:</div>

<div class="output_html rendered_html output_subarea output_execute_result">
*<i>{T,S}</i>(A::<b>AbstractArray{T,2}</b>,x::<b>AbstractArray{S,1}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/linalg/matmul.jl#L71" target="_blank">linalg/matmul.jl:71</a>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><strong>Exercise</strong>: Use the <em>power method</em> to calculate the largest eigenvalue $\lambda_1$ of the matrix $M = \begin{pmatrix} 2 &amp; 1 \\ 1 &amp; 1 \end{pmatrix}$. In this method, we start from an arbitrary non-zero vector $\mathbf{w}$, and repeatedly apply $M$ to it, thus calculating powers of the matrix $M$ applied to $\mathbf{w}$. The resulting vector converges to the eigenvector $\mathbf{v}_1$ corresponding to $\lambda_1$.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [134]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">w</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1.</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
<span class="n">M</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">([</span><span class="mf">2.</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>

<span class="n">M</span><span class="p">,</span> <span class="n">w</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[134]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>(
2x2 Array{Float64,2}:
 2.0  1.0
 1.0  1.0,

[1.0,1.0])</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [135]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">eig</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[135]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>([0.381966,2.61803],
2x2 Array{Float64,2}:
  0.525731  -0.850651
 -0.850651  -0.525731)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [136]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>eig
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.eig(A,[irange,][vl,][vu,][permute=true,][scale=true]) -&gt; D, V

   Computes eigenvalues and eigenvectors of "A". See "eigfact()"
   for details on the "balance" keyword argument.

      julia&gt; eig([1.0 0.0 0.0; 0.0 3.0 0.0; 0.0 0.0 18.0])
      ([1.0,3.0,18.0],
      3x3 Array{Float64,2}:
       1.0  0.0  0.0
       0.0  1.0  0.0
       0.0  0.0  1.0)

   "eig" is a wrapper around "eigfact()", extracting all parts of
   the factorization to a tuple; where possible, using "eigfact()"
   is recommended.

Base.eig(A, B) -&gt; D, V

   Computes generalized eigenvalues and vectors of "A" with respect
   to "B".

   "eig" is a wrapper around "eigfact()", extracting all parts of
   the factorization to a tuple; where possible, using "eigfact()"
   is recommended.
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [137]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">w0</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1.</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
<span class="n">w</span> <span class="o">=</span> <span class="n">copy</span><span class="p">(</span><span class="n">w0</span><span class="p">)</span>

<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="mi">1</span><span class="p">:</span><span class="mi">10</span>
    <span class="n">w_new</span> <span class="o">=</span> <span class="n">M</span><span class="o">*</span><span class="n">w</span>
    <span class="n">println</span><span class="p">(</span><span class="n">w_new</span><span class="p">)</span>
<span class="n">end</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>[3.0,2.0]
[3.0,2.0]
[3.0,2.0]
[3.0,2.0]
[3.0,2.0]
[3.0,2.0]
[3.0,2.0]
[3.0,2.0]
[3.0,2.0]
[3.0,2.0]
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [138]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">for</span> <span class="n">i</span> <span class="o">=</span><span class="mi">1</span><span class="p">:</span><span class="mi">10</span>
    <span class="n">t</span> <span class="o">=</span> <span class="mi">3</span>
<span class="n">end</span>
<span class="n">t</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[138]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Linear-algebra">Linear algebra<a class="anchor-link" href="introduction-to-julia.html#Linear-algebra">¶</a>
</h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Julia has built-in linear algebra, not only using LAPACK, but now also generic routines that work for arbitrary element types, implemented completely in Julia.</p>
<p>For example, given a matrix $A$, the LU-decomposition of $A$ is equivalent to Gaussian elimination; it expresses $A$ as the product $A = LU$, with $L$ a lower-triangular and $U$ an upper-triangular matrix.</p>
<p>This is <em>implemented in pure Julia</em> for arbitrary element types. When the elements are standard floating-point numbers, it uses the corresponding fast LAPACK implementation.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [139]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span> <span class="o">=</span> <span class="n">rand</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="n">eig</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[139]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>(Complex{Float64}[50.0183+0.0im,1.84743+2.30961im,1.84743-2.30961im,-2.72534+0.880116im,-2.72534-0.880116im,-2.86948+0.0im,2.64375+0.964703im,2.64375-0.964703im,2.79553+0.0im,0.196765+2.72857im  …  -0.867929-0.457136im,0.478782+0.882849im,0.478782-0.882849im,-0.120951+0.762254im,-0.120951-0.762254im,-0.54004+0.0im,0.471338+0.0im,0.165157+0.118936im,0.165157-0.118936im,-0.288467+0.0im],
100x100 Array{Complex{Float64},2}:
  -0.101511+0.0im   -0.0115356-0.039612im    …   -0.0524037+0.0im
 -0.0952353+0.0im   0.00489796-0.00599155im      -0.0682674+0.0im
  -0.108918+0.0im    0.0161753-0.092386im         -0.114214+0.0im
  -0.111416+0.0im     0.102416+0.0351175im        -0.103224+0.0im
 -0.0977978+0.0im   -0.0198729+0.0722435im      -0.00218148+0.0im
 -0.0836507+0.0im     0.082544+0.0627261im   …    -0.036751+0.0im
 -0.0963353+0.0im   -0.0388372+0.0032277im        0.0954342+0.0im
 -0.0929018+0.0im     0.029581+0.0575031im        0.0794094+0.0im
  -0.108383+0.0im   -0.0832873-0.160539im         0.0634216+0.0im
 -0.0902722+0.0im   -0.0375187+0.0593948im       -0.0071044+0.0im
   -0.10374+0.0im    -0.102945+0.00231717im  …   -0.0538666+0.0im
  -0.106464+0.0im    -0.104489-0.00207164im      -0.0406458+0.0im
 -0.0960566+0.0im    0.0159221-0.049508im          -0.16083+0.0im
           ⋮                                 ⋱                   
 -0.0946263+0.0im   -0.0375218+0.0672119im          -0.1078+0.0im
 -0.0908183+0.0im  -0.00540686+0.142578im           0.12745+0.0im
  -0.104126+0.0im   -0.0670472+0.0553909im   …    -0.158563+0.0im
 -0.0999715+0.0im    0.0382579-0.0947829im       -0.0696019+0.0im
 -0.0986926+0.0im    -0.084612-0.12682im           0.262889+0.0im
 -0.0949404+0.0im   -0.0400257+0.023941im          -0.11199+0.0im
  -0.107486+0.0im   -0.0344824-0.0759473im         0.087478+0.0im
 -0.0944187+0.0im    -0.021001+0.0461968im   …    0.0110733+0.0im
 -0.0999898+0.0im    0.0392409-0.0264316im       0.00222877+0.0im
 -0.0991767+0.0im  -0.00947725+0.0518241im        0.0205667+0.0im
  -0.108745+0.0im    0.0184766-0.0401366im         0.232166+0.0im
 -0.0993031+0.0im    0.0796098-0.0182621im        0.0712234+0.0im)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [140]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span> <span class="o">=</span> <span class="n">rand</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="n">M2</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="n">big</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[140]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>100x100 Array{BigFloat,2}:
 2.225506282223690401878002376179210841655731201171875e-01  …  6.56851621473254265737296009319834411144256591796875e-01 
 7.319635804294619685350653526256792247295379638671875e-01     9.672824011227445506477806702605448663234710693359375e-01
 5.340947103998476830355457423138432204723358154296875e-01     9.836664954220417644847884730552323162555694580078125e-01
 3.162661116152143403468244287068955600261688232421875e-01     6.32452881486862406035243111546151340007781982421875e-01 
 2.223050262746237848432429018430411815643310546875e-01        9.4728250126541180264894137508235871791839599609375e-02  
 9.375878604020722040246482720249332487583160400390625e-01  …  5.216604894602110409351780617726035416126251220703125e-01
 2.82637383973149969307314677280373871326446533203125e-02      7.1043767348334707634194273850880563259124755859375e-01  
 9.31414288307105042719058474176563322544097900390625e-01      6.843501947718078071147829177789390087127685546875e-01   
 9.08755575606785992448521938058547675609588623046875e-01      7.7541670796339889903947550919838249683380126953125e-02  
 9.90974279386318102069708402268588542938232421875e-01         3.446265247750661675496530733653344213962554931640625e-01
 3.62011301348933667298979344195686280727386474609375e-01   …  5.674886600100188527306954711093567311763763427734375e-01
 9.70427871977250333657138980925083160400390625e-01            1.845040577422647487537687993608415126800537109375e-01   
 9.0041572068816577711913851089775562286376953125e-02          2.86408155710278666816748227574862539768218994140625e-01 
 ⋮                                                          ⋱                                                           
 5.51151260187439984150614691316150128841400146484375e-01      3.306386894959143507577437048894353210926055908203125e-01
 3.497623439347330442927841431810520589351654052734375e-01     8.4233377002282594503412838093936443328857421875e-01     
 2.454565323093833573153688121237792074680328369140625e-01  …  3.436356112336635959536579321138560771942138671875e-01   
 9.3207496351350638263966175145469605922698974609375e-01       7.007260372885506516382747577154077589511871337890625e-01
 8.144309263423663569625432501197792589664459228515625e-01     3.333819991414610495183978855493478477001190185546875e-01
 7.57929320416632634760389919392764568328857421875e-02         6.67666265761114541277265743701718747615814208984375e-01 
 6.366199276186090827422958682291209697723388671875e-01        3.03926419592160268479119622497819364070892333984375e-01 
 5.72819224497360668379997150623239576816558837890625e-01   …  6.6274981934506360659042911720462143421173095703125e-01  
 9.56949160642551976962977278162725269794464111328125e-01      8.29108303980233163343882551998831331729888916015625e-01 
 7.970001203346741558419807915925048291683197021484375e-01     1.888462575949938493380386717035435140132904052734375e-01
 9.0568890895109799288320573396049439907073974609375e-01       4.966056054863334789928330792463384568691253662109375e-01
 2.048115155536647247203063670895062386989593505859375e-01     3.74601565881409026559367703157477080821990966796875e-01 </pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [141]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>map
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.map(f, c...) -&gt; collection

   Transform collection "c" by applying "f" to each element. For
   multiple collection arguments, apply "f" elementwise.

      julia&gt; map((x) -&gt; x * 2, [1, 2, 3])
      3-element Array{Int64,1}:
       2
       4
       6

      julia&gt; map(+, [1, 2, 3], [10, 20, 30])
      3-element Array{Int64,1}:
       11
       22
       33
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [142]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">lu</span><span class="p">(</span><span class="n">M2</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[142]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>(
100x100 Array{BigFloat,2}:
 1e+00                                                                                 …  0e+00
 1.838523316026038069423294824104585502107622762920382948468461321049017107287582e-01     0e+00
 2.226652672640778428153578974542223057899272696712333628373710024305295178288089e-01     0e+00
 8.800271373546953526824682655928247523713656239133309029931077636194740548240004e-01     0e+00
 9.969711511643861050008990963774833601635694233722855443788571591033609498720476e-01     0e+00
 8.979138730555442894457974595685742086077359813056139849438793026237408391767279e-01  …  0e+00
 6.807588600102166833365124716208762430663471006732089118695641612340596096693672e-01     0e+00
 2.455829705129951553304067727592573195211437393497849255275277512239547428646326e-01     0e+00
 7.733884474442739333431587703752807939448278524827717594937087861232859025738641e-01     0e+00
 6.369478597346308029171973720850203624729145464284684008762430813593740043172259e-01     0e+00
 2.827829745702584616783062241061194670528384475163341040075224413128537647704774e-02  …  0e+00
 6.8916911836155407719497226896317385232855759890401728866826844091322063237215e-02       0e+00
 9.914847445449848621627477787268697917524046066273956341540063379389126840704449e-01     0e+00
 ⋮                                                                                     ⋱       
 5.917560795509736662262312292818648981295636865290101585946113867783160165303854e-01     0e+00
 2.730343465699633349451394482373398269247854760360330831523299677598397581623309e-01     0e+00
 9.039945797670267226102309624603231261343146722095674272138480977753157246173324e-01  …  0e+00
 9.462017626922501325170145941450688057814574666304378855494052732254706598746676e-01     0e+00
 7.922089379792833548468864680973299515938762464750620693002149619341420960071084e-01     0e+00
 8.91312804253419886178066534318762609663940375583837777475766448455788684217046e-01      0e+00
 2.792642705237073137742461219913623698283706391737491380867611670762794730952418e-05     0e+00
 7.573650294135219377704801284400430317640792346704970287945898791774355476300744e-01  …  0e+00
 4.340348981096360281012666931631459479552193700232478278658625428081540612698508e-01     0e+00
 8.425932003310413942243844696491498599262760249784090231673454808048725464374257e-01     0e+00
 9.574420989713105503105950862187424587135981099834153833267817582826759295038591e-01     0e+00
 9.937128828323402433568347457741518522388968395097111212977949553756464564214356e-01     1e+00,

100x100 Array{BigFloat,2}:
 9.994851507686071112601666754926554858684539794921875e-01  …   5.00779152589674314555168166407383978366851806640625e-02                            
 0e+00                                                          5.957614820766671895663417312682526372739723842260882343182715867242722586063138e-01
 0e+00                                                          4.469478342275836995433682687239315802830255734475567159873597681467845826134468e-01
 0e+00                                                          1.594225612955579740227438886545435994704893579284040834538915577684978835022275e-01
 0e+00                                                          3.51418102474667774543916344035850933636933755274101969213535739730486430086481e-01 
 0e+00                                                      …   3.853995991912961375481683208700128985955666356716160345936599990779107394373079e-01
 0e+00                                                         -1.388928850457794922700969846901469586577590670720174042695508511464725140648597e-01
 0e+00                                                         -1.963736253744149588710187786364289757425844420781275911168560619527357939135026e-01
 0e+00                                                          3.178968402329430072315582253427327119635802392272492696354540300940096734477185e-01
 0e+00                                                          2.176214988150537681248929128626937855865936488765697272966015579849791295536862e-01
 0e+00                                                      …   5.119997557073573321754864325074991553008298165056610101108332375190160965916915e-01
 0e+00                                                         -8.199420519824984131304944439473283677509641603892215267311260421539949314147843e-02
 0e+00                                                         -1.100757926861985762949819942253220494124734219500225416371630465493477225668268e+00
 ⋮                                                          ⋱                                                                                       
 0e+00                                                          3.119374583443352091823412074951378032702116370133229255033911885197311498449721e-01
 0e+00                                                         -3.963473902224899280333406215892276084125185726495321949218801950999434601486697e-01
 0e+00                                                      …   1.460022051064841242988743472828596892824793640959853693084700574539034836575632e+00
 0e+00                                                          9.460562261692564028602511319807472584567333376119182633775041922970959644819617e-01
 0e+00                                                          1.916100769270754349291340364996423402303124329778281922547647681942010509253265e+00
 0e+00                                                          2.453777141130431399782611832707715011759461721288957685494547893432872020437905e+00
 0e+00                                                          3.092241770787052786375610695487741355942081214332538992688100491955019679622272e-01
 0e+00                                                      …  -7.690085518435571170493252506836527889003361725238261885731324700815770035046439e-01
 0e+00                                                          7.057077397497909132059254043595925169793816268455912227899415362222622859241975e-01
 0e+00                                                          2.11408055146617577269295905987997866661481241577267775907335892526116912022093e-01 
 0e+00                                                          4.72135706225358566629488251105981838448104777282753072505691201455089121862885e-01 
 0e+00                                                         -1.411605504403213576549449087599331540683320578509496538094218931547453928045177e+00,

[41,78,1,52,36,63,62,91,21,95  …  67,34,76,69,31,77,28,82,97,58])</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [143]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">lu</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[143]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>(
100x100 Array{Float64,2}:
 1.0         0.0         0.0         0.0        …   0.0       0.0       0.0
 0.183852    1.0         0.0         0.0            0.0       0.0       0.0
 0.222665    0.333612    1.0         0.0            0.0       0.0       0.0
 0.880027    0.908157    0.485849    1.0            0.0       0.0       0.0
 0.996971    0.0121974   0.880719    0.482328       0.0       0.0       0.0
 0.897914    0.688716   -0.173968   -0.535249   …   0.0       0.0       0.0
 0.680759    0.256184    0.805169    0.0615926      0.0       0.0       0.0
 0.245583    0.122523    0.852098    0.230656       0.0       0.0       0.0
 0.773388    0.783385    0.294589    0.813216       0.0       0.0       0.0
 0.636948    0.621283   -0.464593    0.0427875      0.0       0.0       0.0
 0.0282783   0.895956   -0.28519    -0.723122   …   0.0       0.0       0.0
 0.0689169   0.529095    0.623271    0.567317       0.0       0.0       0.0
 0.991485    0.723194   -0.0744293   0.0926657      0.0       0.0       0.0
 ⋮                                              ⋱                          
 0.591756    0.553754    0.585172    0.792699       0.0       0.0       0.0
 0.273034    0.946579    0.312432    0.252827       0.0       0.0       0.0
 0.903995    0.190557    0.113748   -0.253964   …   0.0       0.0       0.0
 0.946202    0.644426    0.227142    0.306999       0.0       0.0       0.0
 0.792209    0.616671    0.267607    0.875396       0.0       0.0       0.0
 0.891313    0.895161    0.31949     0.0199976      0.0       0.0       0.0
 2.79264e-5  0.187737    0.926009    0.460432       0.0       0.0       0.0
 0.757365    0.538407    0.300644    0.140578   …   0.0       0.0       0.0
 0.434035    0.293604    0.46559     0.452693       0.0       0.0       0.0
 0.842593    0.325906    0.090703    0.620878       1.0       0.0       0.0
 0.957442    0.628242    0.0057032  -0.198115      -0.163927  1.0       0.0
 0.993713    0.465608   -0.431142   -0.125049      -0.617413  0.640633  1.0,

100x100 Array{Float64,2}:
 0.999485  0.0617704  0.296413  …   0.536738     0.579976    0.0500779
 0.0       0.964559   0.333478     -0.0592369   -0.0351511   0.595761 
 0.0       0.0        0.756701      0.751446     0.616732    0.446948 
 0.0       0.0        0.0          -0.572233    -0.401953    0.159423 
 0.0       0.0        0.0          -0.097152    -0.229394    0.351418 
 0.0       0.0        0.0       …   0.171652     0.103321    0.3854   
 0.0       0.0        0.0          -0.823456    -0.31806    -0.138893 
 0.0       0.0        0.0           0.346634     0.117767   -0.196374 
 0.0       0.0        0.0           0.114205     0.694677    0.317897 
 0.0       0.0        0.0           0.18621      0.454778    0.217621 
 0.0       0.0        0.0       …   0.875338     1.06396     0.512    
 0.0       0.0        0.0          -0.666298    -0.761167   -0.0819942
 0.0       0.0        0.0          -0.463261    -0.622826   -1.10076  
 ⋮                              ⋱                                     
 0.0       0.0        0.0           1.10803     -2.71365     0.311937 
 0.0       0.0        0.0           1.55302     -4.63257    -0.396347 
 0.0       0.0        0.0       …   0.00811131  -1.63731     1.46002  
 0.0       0.0        0.0           0.959823    -1.79163     0.946056 
 0.0       0.0        0.0           2.08064      0.0531956   1.9161   
 0.0       0.0        0.0           0.803113    -1.73451     2.45378  
 0.0       0.0        0.0          -1.11381      0.340109    0.309224 
 0.0       0.0        0.0       …   1.40266      0.277447   -0.769009 
 0.0       0.0        0.0          -1.36105      0.370272    0.705708 
 0.0       0.0        0.0          -1.64671      0.297193    0.211408 
 0.0       0.0        0.0           0.0          1.00489     0.472136 
 0.0       0.0        0.0           0.0          0.0        -1.41161  ,

[41,78,1,52,36,63,62,91,21,95  …  67,34,76,69,31,77,28,82,97,58])</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [144]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>lu
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.lu(A) -&gt; L, U, p

   Compute the LU factorization of "A", such that "A[p,:] = L*U".
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [145]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">methods</span><span class="p">(</span><span class="n">lu</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[145]:</div>

<div class="output_html rendered_html output_subarea output_execute_result">
2 methods for generic function <b>lu</b>:<ul>
<li> lu(x::<b>Number</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/linalg/lu.jl#L69" target="_blank">linalg/lu.jl:69</a>
</li>
<li> lu(A::<b>AbstractArray{T,2}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/linalg/lu.jl#L71" target="_blank">linalg/lu.jl:71</a>
</li>
</ul>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [146]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># @edit lu(M)</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [147]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>edit
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.edit(file::String[, line])

   Edit a file optionally providing a line number to edit at. Returns
   to the julia prompt when you quit the editor.

Base.edit(function[, types])

   Edit the definition of a function, optionally specifying a tuple of
   types to indicate which method to edit.
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Interacting-with-the-system">Interacting with the system<a class="anchor-link" href="introduction-to-julia.html#Interacting-with-the-system">¶</a>
</h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Command-line-arguments">Command-line arguments<a class="anchor-link" href="introduction-to-julia.html#Command-line-arguments">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>A Julia script, similar to a Python script, is a sequence of Julia commands placed in a file, with the termination <code>.jl</code>.</p>
<p>From the command line, a script <code>script.jl</code> can be run as</p>

<pre><code>julia script.jl arg1 arg2 

</code></pre>
<p>where <code>arg1</code> and <code>arg2</code> are command-line arguments.</p>
<p>These command-line arguments to Julia scripts are placed in the variable <code>ARGS</code> as an array of strings.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Files">Files<a class="anchor-link" href="introduction-to-julia.html#Files">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Simple file input and output is easy:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [148]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">outfile</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s2">"test.txt"</span><span class="p">,</span> <span class="s2">"w"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[148]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>IOStream(&lt;file test.txt&gt;)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [149]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="mi">1</span><span class="p">:</span><span class="mi">10</span>
    <span class="n">println</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="s2">"The value of i is $i"</span><span class="p">)</span>
<span class="n">end</span>

<span class="n">close</span><span class="p">(</span><span class="n">outfile</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [150]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="p">;</span><span class="n">cat</span> <span class="n">test</span><span class="o">.</span><span class="n">txt</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>The value of i is 1
The value of i is 2
The value of i is 3
The value of i is 4
The value of i is 5
The value of i is 6
The value of i is 7
The value of i is 8
The value of i is 9
The value of i is 10
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [151]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">infile</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s2">"test.txt"</span><span class="p">,</span> <span class="s2">"r"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[151]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>IOStream(&lt;file test.txt&gt;)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [152]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">lines</span> <span class="o">=</span> <span class="n">readlines</span><span class="p">(</span><span class="n">infile</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[152]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>10-element Array{Union(UTF8String,ASCIIString),1}:
 "The value of i is 1\n" 
 "The value of i is 2\n" 
 "The value of i is 3\n" 
 "The value of i is 4\n" 
 "The value of i is 5\n" 
 "The value of i is 6\n" 
 "The value of i is 7\n" 
 "The value of i is 8\n" 
 "The value of i is 9\n" 
 "The value of i is 10\n"</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [153]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">map</span><span class="p">(</span><span class="n">split</span><span class="p">,</span> <span class="n">lines</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[153]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>10-element Array{Array{SubString{ASCIIString},1},1}:
 SubString{ASCIIString}["The","value","of","i","is","1"] 
 SubString{ASCIIString}["The","value","of","i","is","2"] 
 SubString{ASCIIString}["The","value","of","i","is","3"] 
 SubString{ASCIIString}["The","value","of","i","is","4"] 
 SubString{ASCIIString}["The","value","of","i","is","5"] 
 SubString{ASCIIString}["The","value","of","i","is","6"] 
 SubString{ASCIIString}["The","value","of","i","is","7"] 
 SubString{ASCIIString}["The","value","of","i","is","8"] 
 SubString{ASCIIString}["The","value","of","i","is","9"] 
 SubString{ASCIIString}["The","value","of","i","is","10"]</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [154]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">6</span><span class="p">])</span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="nb">map</span><span class="p">(</span><span class="n">split</span><span class="p">,</span> <span class="n">lines</span><span class="p">)]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[154]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>10-element Array{Any,1}:
  1.0
  2.0
  3.0
  4.0
  5.0
  6.0
  7.0
  8.0
  9.0
 10.0</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [155]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">rand</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[155]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>5x5 Array{Float64,2}:
 0.494374  0.548784    0.265116  0.14175    0.225112 
 0.610879  0.863226    0.90218   0.905241   0.0066329
 0.352839  0.163394    0.514312  0.46365    0.750558 
 0.72891   0.539688    0.37556   0.0172088  0.0674222
 0.069424  0.00747654  0.951597  0.984837   0.350702 </pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [156]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">writedlm</span><span class="p">(</span><span class="s2">"random.txt"</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [157]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="p">;</span><span class="n">cat</span> <span class="n">random</span><span class="o">.</span><span class="n">txt</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>.49437356567549995	.5487835147411582	.2651160558475778	.1417496876038895	.22511205695160474
.6108787919798604	.863226095224578	.9021796958394908	.9052411849611	.006632897854429665
.3528390706690816	.16339401668213926	.5143118341066373	.4636496583658838	.7505578231005474
.7289100209460473	.5396877767037889	.37555992341554356	.017208754116336156	.06742216219992869
.069423968121745	.007476542969398592	.9515968215572792	.9848367987309561	.35070195619498623
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [158]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="n">readdlm</span><span class="p">(</span><span class="s2">"random.txt"</span><span class="p">)</span>  <span class="c1"># note that tab completion works for files</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[158]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>5x5 Array{Float64,2}:
 0.494374  0.548784    0.265116  0.14175    0.225112 
 0.610879  0.863226    0.90218   0.905241   0.0066329
 0.352839  0.163394    0.514312  0.46365    0.750558 
 0.72891   0.539688    0.37556   0.0172088  0.0674222
 0.069424  0.00747654  0.951597  0.984837   0.350702 </pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [159]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>writedlm
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.writedlm(f, A, delim='t')

   Write "A" (either an array type or an iterable collection of
   iterable rows) as text to "f" (either a filename string or an
   "IO" stream) using the given delimeter "delim" (which defaults
   to tab, but can be any printable Julia object, typically a "Char"
   or "String").

   For example, two vectors "x" and "y" of the same length can be
   written as two columns of tab-delimited text to "f" by either
   "writedlm(f, [x y])" or by "writedlm(f, zip(x, y))".
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [160]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>readdlm
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.readdlm(source, delim::Char, T::Type, eol::Char; header=false, skipstart=0, skipblanks=true, use_mmap, ignore_invalid_chars=false, quotes=true, dims, comments=true, comment_char='#')

   Read a matrix from the source where each line (separated by
   "eol") gives one row, with elements separated by the given
   delimeter. The source can be a text file, stream or byte array.
   Memory mapped files can be used by passing the byte array
   representation of the mapped segment as source.

   If "T" is a numeric type, the result is an array of that type,
   with any non-numeric elements as "NaN" for floating-point types,
   or zero. Other useful values of "T" include "ASCIIString",
   "String", and "Any".

   If "header" is "true", the first row of data will be read as
   header and the tuple "(data_cells, header_cells)" is returned
   instead of only "data_cells".

   Specifying "skipstart" will ignore the corresponding number of
   initial lines from the input.

   If "skipblanks" is "true", blank lines in the input will be
   ignored.

   If "use_mmap" is "true", the file specified by "source" is
   memory mapped for potential speedups. Default is "true" except on
   Windows. On Windows, you may want to specify "true" if the file
   is large, and is only read once and not written to.

   If "ignore_invalid_chars" is "true", bytes in "source" with
   invalid character encoding will be ignored. Otherwise an error is
   thrown indicating the offending character position.

   If "quotes" is "true", column enclosed within double-quote (``)
   characters are allowed to contain new lines and column delimiters.
   Double-quote characters within a quoted field must be escaped with
   another double-quote.

   Specifying "dims" as a tuple of the expected rows and columns
   (including header, if any) may speed up reading of large files.

   If "comments" is "true", lines beginning with "comment_char"
   and text following "comment_char" in any line are ignored.

Base.readdlm(source, delim::Char, eol::Char; options...)

   If all data is numeric, the result will be a numeric array. If some
   elements cannot be parsed as numbers, a cell array of numbers and
   strings is returned.

Base.readdlm(source, delim::Char, T::Type; options...)

   The end of line delimiter is taken as "\n".

Base.readdlm(source, delim::Char; options...)

   The end of line delimiter is taken as "\n". If all data is
   numeric, the result will be a numeric array. If some elements
   cannot be parsed as numbers, a cell array of numbers and strings is
   returned.

Base.readdlm(source, T::Type; options...)

   The columns are assumed to be separated by one or more whitespaces.
   The end of line delimiter is taken as "\n".

Base.readdlm(source; options...)

   The columns are assumed to be separated by one or more whitespaces.
   The end of line delimiter is taken as "\n". If all data is
   numeric, the result will be a numeric array. If some elements
   cannot be parsed as numbers, a cell array of numbers and strings is
   returned.
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h4 id="Shelling-out">Shelling out<a class="anchor-link" href="introduction-to-julia.html#Shelling-out">¶</a>
</h4>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [161]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="p">;</span><span class="n">ls</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Example of defining a new type.ipynb
fractal_example
helllo_julia.png
Index.ipynb
Install IPython Notebook.md
Install Julia.md
Install Julia Packages.md
Interoperability with Python and C.ipynb
Introduction to Julia.ipynb
intro.txt
julia_tutorial.md
Metaprogramming.ipynb
Packages and graphics in Julia.ipynb
Performance in Julia.ipynb
Plan of the tutorial.ipynb
random.txt
README.md
stuff.pdf
test.txt
Vector2d.jl
What's next.ipynb
Why Julia.ipynb
Why Julia.slides.html
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [162]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">run</span><span class="p">(</span><span class="err">`</span><span class="n">echo</span> <span class="n">Hello</span><span class="err">`</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Hello
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Scientific-computing">Scientific computing<a class="anchor-link" href="introduction-to-julia.html#Scientific-computing">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Linear algebra, FFT, random numbers, special functions.
Packages for optimization, ODEs etc.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Functions">Functions<a class="anchor-link" href="introduction-to-julia.html#Functions">¶</a>
</h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Functions may be defined using the short syntax <code>f(x) = 3x + 1</code> or using a longer form:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [163]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">dup</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">=</span> <span class="mi">2</span><span class="n">x</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[163]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>dup (generic function with 1 method)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [164]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">function</span> <span class="n">duplicate</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
    <span class="mi">2</span><span class="n">x</span>   <span class="c1"># no explicit "return" needed</span>
<span class="n">end</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[164]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>duplicate (generic function with 1 method)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>The last value computed in the function is automatically returned; no explicit <code>return</code> statement is required.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [165]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">duplicate</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">=</span> <span class="n">x</span><span class="o">^</span><span class="mi">2</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[165]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>duplicate (generic function with 1 method)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Every operator in Julia is a function. Functions are implemented by specifying their action on different <em>types</em>. Until now, we have written only functions that are generic, in the sense that they do not specify which type they accept, and as in Python they will work as long as the operations performed in them make sense for the input value:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [166]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">duplicate</span><span class="p">(</span><span class="mi">3</span><span class="p">),</span> <span class="n">duplicate</span><span class="p">(</span><span class="mf">3.5</span><span class="p">),</span> <span class="n">duplicate</span><span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="mi">3</span><span class="n">im</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[166]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>(9,12.25,-8 + 6im)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [167]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">duplicate</span><span class="p">(</span><span class="s2">"Hola"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[167]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>"HolaHola"</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [168]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mi">2</span> <span class="o">*</span> <span class="s2">"Hola"</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
`*` has no method matching *(::Int64, ::ASCIIString)
while loading In[168], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Note that string concatenation uses the <code>*</code> operator in Julia, instead of the <code>+</code> operator as in Python.
Repeating a string is thus done by raising to an integer power:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [169]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="s2">"Hello"</span><span class="o">^</span><span class="mi">2</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[169]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>"HelloHello"</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>As a simple example, suppose that we wish to concatenate two strings. In Python we would write:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [170]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">s1</span> <span class="o">=</span> <span class="s2">"Hello, "</span>
<span class="n">s2</span> <span class="o">=</span> <span class="s2">"David"</span>

<span class="n">s1</span> <span class="o">+</span> <span class="n">s2</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
`+` has no method matching +(::ASCIIString, ::ASCIIString)
while loading In[170], in expression starting on line 4
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>However, we see that in Julia, summation is not defined for strings. What is it defined for?</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [171]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">+</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[171]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>+ (generic function with 148 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>We see that <code>+</code> is treated as a function, and that it has a multitude of <em>methods</em>, which, in Julia, are specialised versions of the function that act on different types:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>If we were unaware of the <code>*</code> operator for string concatenation, we could just <em>define our own</em> <code>+</code> for the concatenation of two strings:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [173]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">+</span><span class="p">(</span><span class="n">s1</span><span class="p">::</span><span class="n">String</span><span class="p">,</span> <span class="n">s2</span><span class="p">::</span><span class="n">String</span><span class="p">)</span> <span class="o">=</span> <span class="n">string</span><span class="p">(</span><span class="n">s1</span><span class="p">,</span> <span class="n">s2</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[173]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>+ (generic function with 149 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [174]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="s2">"First"</span> <span class="o">+</span> <span class="s2">" second"</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[174]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>"First second"</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>However, we cannot add a number to a string, since we have not (yet) defined it:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [175]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="s2">"The value of x is "</span> <span class="o">+</span> <span class="mi">3</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
`+` has no method matching +(::ASCIIString, ::Int64)
while loading In[175], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>This we can also define, using the previous new definition:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [176]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">+</span><span class="p">(</span><span class="n">s</span><span class="p">::</span><span class="n">String</span><span class="p">,</span> <span class="n">x</span><span class="p">::</span><span class="n">Number</span><span class="p">)</span> <span class="o">=</span> <span class="n">s</span> <span class="o">+</span> <span class="s2">"$(2x)"</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[176]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>+ (generic function with 150 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [177]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="s2">"The value of x is "</span> <span class="o">+</span> <span class="mi">3</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[177]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>"The value of x is 6"</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [178]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="mf">3.5</span>
<span class="s2">"The value of x is "</span> <span class="o">+</span> <span class="n">x</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[178]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>"The value of x is 7.0"</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [179]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mi">3</span> <span class="o">+</span> <span class="s2">"hello"</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
`+` has no method matching +(::Int64, ::ASCIIString)
while loading In[179], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>In fact, we can define the summation of a string with <em>any</em> other object:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [180]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">+</span><span class="p">(</span><span class="n">s</span><span class="p">::</span><span class="n">String</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span> <span class="o">=</span> <span class="n">s</span> <span class="o">+</span> <span class="n">string</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[180]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>+ (generic function with 151 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [181]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="s2">"Complex "</span> <span class="o">+</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[181]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>"Complex [3,4,5]"</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [182]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="s2">"a"</span> <span class="o">+</span> <span class="mi">3</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[182]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>"a6"</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [183]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">Number</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[183]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Number</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [184]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">typeof</span><span class="p">(</span><span class="n">Number</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[184]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>DataType</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [185]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">super</span><span class="p">(</span><span class="n">Int64</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[185]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Signed</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [186]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">super</span><span class="p">(</span><span class="n">Signed</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[186]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Integer</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [187]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">super</span><span class="p">(</span><span class="n">Integer</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[187]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Real</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [188]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">super</span><span class="p">(</span><span class="n">Real</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[188]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Number</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [189]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">super</span><span class="p">(</span><span class="n">Number</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[189]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Any</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>In this way, the concept of "function" is replaced by a "patchwork" of different definitions for objects of different types, easily modifiable by the user.
This is also exactly the way to define "operator overloading" for user-defined types.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>In the above, we also begin to see the power of <em>multiple dispatch</em>: we defined two methods (versions) of the function <code>+</code>, both with the same <em>number</em> but different <em>types</em> of arguments.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="User-defined-types">User-defined types<a class="anchor-link" href="introduction-to-julia.html#User-defined-types">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>A user-defined "composite type" is a collection of data.
Unlike in Python, types do not "own" methods (functions internal to the type).</p>
<p>Rather, methods are defined separately, and are characterised by the types of <em>all</em> of their arguments; this is known as <em>multiple dispatch</em>. (<em>Dispatch</em> is the process of choosing which "version" of a given function to execute.)</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>A simple, but useful, example, is that of defining a 2D vector type. (See also the <code>ImmutableArrays.jl</code> package; fixed-size arrays will later be incorporated into base Julia.)</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [190]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nd">@which</span> <span class="mi">3</span><span class="o">//</span><span class="mi">4</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[190]:</div>

<div class="output_html rendered_html output_subarea output_execute_result">
//(n::<b>Integer</b>,d::<b>Integer</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/rational.jl#L15" target="_blank">rational.jl:15</a>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [191]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">Rational</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[191]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3//1</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [192]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mi">6</span><span class="o">//</span><span class="mi">4</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[192]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>3//2</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [193]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">im</span><span class="o">*</span><span class="n">im</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[193]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>-1 + 0im</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [194]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">immutable</span> <span class="n">Vector2D</span>   <span class="c1"># type</span>
    <span class="n">x</span><span class="p">::</span><span class="n">Float64</span>
    <span class="n">y</span><span class="p">::</span><span class="n">Float64</span>
<span class="n">end</span> 
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [195]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="n">w</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[195]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Vector2D(5.0,6.0)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [196]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span> <span class="o">+</span> <span class="n">w</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
`+` has no method matching +(::Vector2D, ::Vector2D)
while loading In[196], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [197]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">+</span><span class="p">(</span><span class="n">v</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">,</span> <span class="n">w</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">)</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="n">v</span><span class="o">.</span><span class="n">x</span><span class="o">+</span><span class="n">w</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">v</span><span class="o">.</span><span class="n">y</span><span class="o">+</span><span class="n">w</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[197]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>+ (generic function with 152 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [198]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span> <span class="o">+</span> <span class="n">w</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[198]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Vector2D(8.0,10.0)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [199]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">*</span><span class="p">(</span><span class="n">v</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">,</span> <span class="n">α</span><span class="p">::</span><span class="n">Number</span><span class="p">)</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="n">v</span><span class="o">.</span><span class="n">x</span><span class="o">*</span><span class="n">α</span><span class="p">,</span> <span class="n">v</span><span class="o">.</span><span class="n">y</span><span class="o">*</span><span class="n">α</span><span class="p">)</span>
<span class="o">*</span><span class="p">(</span><span class="n">α</span><span class="p">::</span><span class="n">Number</span><span class="p">,</span> <span class="n">v</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">)</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="n">v</span><span class="o">.</span><span class="n">x</span><span class="o">*</span><span class="n">α</span><span class="p">,</span> <span class="n">v</span><span class="o">.</span><span class="n">y</span><span class="o">*</span><span class="n">α</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[199]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>* (generic function with 126 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [200]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span> <span class="o">*</span> <span class="mf">3.5</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[200]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Vector2D(10.5,14.0)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [201]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mf">3.5</span> <span class="o">*</span> <span class="n">v</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[201]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Vector2D(10.5,14.0)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><strong>Exercise</strong>: 
Define mathematical operations on <code>Vector2D</code>. Define a particle with position and velocity in 2D. Define function <code>move</code> that acts on a particle to move it over a time $\delta t$.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [202]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">immutable</span> <span class="n">VectorT</span>   <span class="c1"># type</span>
    <span class="n">p</span><span class="p">::</span><span class="n">Vector2D</span>
    <span class="n">v</span><span class="p">::</span><span class="n">Vector2D</span>
<span class="n">end</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [203]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="o">=</span> <span class="n">VectorT</span><span class="p">(</span><span class="n">Vector2D</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span><span class="n">Vector2D</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[203]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>VectorT(Vector2D(0.0,0.0),Vector2D(2.0,3.0))</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [204]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">move</span><span class="p">(</span><span class="n">a</span><span class="p">::</span><span class="n">VectorT</span><span class="p">,</span> <span class="n">t</span><span class="p">::</span><span class="n">Number</span><span class="p">)</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">p</span><span class="o">+</span><span class="n">a</span><span class="o">.</span><span class="n">v</span><span class="o">*</span><span class="n">t</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[204]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>move (generic function with 1 method)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [205]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">println</span><span class="p">(</span><span class="s2">"new position of particle $a with origin position $(a.p) and velocity $(a.v) at time 3 is $(move(a, 3))"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>new position of particle VectorT(Vector2D(0.0,0.0),Vector2D(2.0,3.0)) with origin position Vector2D(0.0,0.0) and velocity Vector2D(2.0,3.0) at time 3 is Vector2D(6.0,9.0)
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Here, we have used <code>immutable</code> instead of <code>type</code> for efficiency: the object is stored in an efficient packed form.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>The equivalent of the Python <code>__repr__</code> method for an object is to extend the <code>show</code> method:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [206]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>show
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.show(x)

   Write an informative text representation of a value to the current
   output stream. New types should overload "show(io, x)" where the
   first argument is a stream. The representation used by "show"
   generally includes Julia-specific formatting and type information.
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [207]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">Base.show</span>

<span class="n">show</span><span class="p">(</span><span class="n">io</span><span class="p">::</span><span class="n">IO</span><span class="p">,</span> <span class="n">v</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">)</span> <span class="o">=</span> <span class="nb">print</span><span class="p">(</span><span class="n">io</span><span class="p">,</span> <span class="s2">"[$(v.x), $(v.y)]"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[207]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>show (generic function with 94 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [208]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[208]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>[3.0, 4.0]</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [209]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">+</span><span class="p">(</span><span class="n">v1</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">,</span> <span class="n">v2</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">)</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="n">v1</span><span class="o">.</span><span class="n">x</span><span class="o">+</span><span class="n">v2</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">v1</span><span class="o">.</span><span class="n">y</span><span class="o">+</span><span class="n">v2</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>

<span class="o">*</span><span class="p">(</span><span class="n">v</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">,</span> <span class="n">lamb</span><span class="p">::</span><span class="n">Number</span><span class="p">)</span>  <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="n">lamb</span><span class="o">*</span><span class="n">v</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">lamb</span><span class="o">*</span><span class="n">v</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[209]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>* (generic function with 126 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>We can confirm that the new method for the function <code>+</code> has indeed been defined:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [211]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>

<span class="n">x</span> <span class="o">+</span> <span class="n">y</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[211]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>[8.0, 10.0]</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Parametrised-types">Parametrised types<a class="anchor-link" href="introduction-to-julia.html#Parametrised-types">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Types may have a parameter, for example:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [212]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">immutable</span> <span class="n">Vector2D</span><span class="p">{</span><span class="n">T</span> <span class="o">&lt;</span><span class="p">:</span> <span class="n">Real</span><span class="p">}</span> <span class="c1">#must same type T</span>
    <span class="n">x</span><span class="p">::</span><span class="n">T</span>
    <span class="n">y</span><span class="p">::</span><span class="n">T</span>
<span class="n">end</span> 
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
invalid redefinition of constant Vector2D
while loading In[212], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><code>T</code> is a type parameter.
The expression <code>T &lt;: Real</code> means that <code>T</code> must be a subtype of the abstract type <code>Real</code>.
We can investigate the type hierarchy with the <code>super</code> function:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [213]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">Integer</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[213]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Integer</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [214]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">super</span><span class="p">(</span><span class="n">Integer</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[214]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Real</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [215]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">super</span><span class="p">(</span><span class="n">Real</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[215]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Number</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [216]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">super</span><span class="p">(</span><span class="n">Number</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[216]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Any</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [217]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="mf">3.</span><span class="p">,</span> <span class="mf">4.</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[217]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>[3.0, 4.0]</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [218]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mf">4.</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[218]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>[3.0, 4.0]</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Here, the types of the two arguments were different, so there is no match for the type signature.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [219]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="mi">3</span><span class="o">//</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="o">//</span><span class="mi">6</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[219]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>[0.75, 0.8333333333333334]</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [220]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">Base.show</span>
<span class="n">show</span><span class="p">{</span><span class="n">T</span><span class="p">}(</span><span class="n">io</span><span class="p">::</span><span class="n">IO</span><span class="p">,</span> <span class="n">v</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">{</span><span class="n">T</span><span class="p">})</span> <span class="o">=</span> <span class="nb">print</span><span class="p">(</span><span class="n">io</span><span class="p">,</span> <span class="s2">"[$(v.x), $(v.y)]"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
too many parameters for type Vector2D
while loading In[220], in expression starting on line 2
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [221]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">v</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[221]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>[0.75, 0.8333333333333334]</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>We can define <em>outer constructors</em>, defined outside the type definition itself, which allow other ways of constructing the object:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [222]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">Vector2D</span><span class="p">{</span><span class="n">T</span><span class="p">}(</span><span class="n">x</span><span class="p">::</span><span class="n">T</span><span class="p">)</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[222]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Vector2D (constructor with 3 methods)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [223]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">Vector2D</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[223]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>[3.0, 3.0]</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Example:-a-simple-type-for-a-collection-of-particles">Example: a simple type for a collection of particles<a class="anchor-link" href="introduction-to-julia.html#Example:-a-simple-type-for-a-collection-of-particles">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Let's define a particle:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [224]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">type</span> <span class="n">Particle</span>
    <span class="n">position</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">{</span><span class="n">Float64</span><span class="p">}</span>
    <span class="n">velocity</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">{</span><span class="n">Float64</span><span class="p">}</span>
<span class="n">end</span>
<span class="n">move</span><span class="p">(</span><span class="n">p</span><span class="p">::</span><span class="n">Particle</span><span class="p">,</span> <span class="n">dt</span><span class="p">::</span><span class="n">Real</span><span class="p">)</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">position</span> <span class="o">+=</span> <span class="n">p</span><span class="o">.</span><span class="n">velocity</span> <span class="o">*</span> <span class="n">dt</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
too many parameters for type Vector2D
while loading In[224], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [225]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">show</span><span class="p">(</span><span class="n">io</span><span class="p">::</span><span class="n">IO</span><span class="p">,</span> <span class="n">p</span><span class="p">::</span><span class="n">Particle</span><span class="p">)</span> <span class="o">=</span> <span class="nb">print</span><span class="p">(</span><span class="n">io</span><span class="p">,</span> <span class="s2">"pos: $(p.position); vel: $(p.velocity)"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
Particle not defined
while loading In[225], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [226]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">p</span> <span class="o">=</span> <span class="n">Particle</span><span class="p">(</span><span class="n">Vector2D</span><span class="p">(</span><span class="mf">0.</span><span class="p">,</span><span class="mf">0.</span><span class="p">),</span> <span class="n">Vector2D</span><span class="p">(</span><span class="mf">1.</span><span class="p">,</span><span class="mf">1.</span><span class="p">))</span>
<span class="o">+</span><span class="p">{</span><span class="n">T</span><span class="p">}(</span><span class="n">v1</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">{</span><span class="n">T</span><span class="p">},</span> <span class="n">v2</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">{</span><span class="n">T</span><span class="p">})</span> <span class="o">=</span> <span class="n">Vector2D</span><span class="p">{</span><span class="n">T</span><span class="p">}(</span><span class="n">v1</span><span class="o">.</span><span class="n">x</span><span class="o">+</span><span class="n">v2</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">v1</span><span class="o">.</span><span class="n">y</span><span class="o">+</span><span class="n">v2</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>

<span class="o">*</span><span class="p">{</span><span class="n">T</span><span class="p">}(</span><span class="n">v</span><span class="p">::</span><span class="n">Vector2D</span><span class="p">{</span><span class="n">T</span><span class="p">},</span> <span class="n">lamb</span><span class="p">::</span><span class="n">Number</span><span class="p">)</span>  <span class="o">=</span> <span class="n">Vector2D</span><span class="p">{</span><span class="n">T</span><span class="p">}(</span><span class="n">lamb</span><span class="o">*</span><span class="n">v</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">lamb</span><span class="o">*</span><span class="n">v</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
Particle not defined
while loading In[226], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [227]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">move</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
p not defined
while loading In[227], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [228]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">p</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
p not defined
while loading In[228], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Now we can define a gas as a collection of particle:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [229]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">Int</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[229]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Int64</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [230]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">type</span> <span class="n">Gas</span>
    <span class="n">particles</span><span class="p">::</span><span class="n">Vector</span><span class="p">{</span><span class="n">Particle</span><span class="p">}</span>  <span class="c1"># Array{Particle, 1}</span>
    
    <span class="n">function</span> <span class="n">Gas</span><span class="p">(</span><span class="n">N</span><span class="p">::</span><span class="n">Integer</span><span class="p">)</span>
        <span class="n">parts</span> <span class="o">=</span> <span class="p">[</span><span class="n">Particle</span><span class="p">(</span><span class="n">Vector2D</span><span class="p">(</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">...</span><span class="p">),</span> <span class="n">Vector2D</span><span class="p">(</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">...</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="mi">1</span><span class="p">:</span><span class="n">N</span><span class="p">]</span>
        <span class="n">new</span><span class="p">(</span><span class="n">parts</span><span class="p">)</span>
    <span class="n">end</span>
<span class="n">end</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
Particle not defined
while loading In[230], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [231]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">show</span><span class="p">(</span><span class="n">io</span><span class="p">::</span><span class="n">IO</span><span class="p">,</span> <span class="n">g</span><span class="p">::</span><span class="n">Gas</span><span class="p">)</span> <span class="o">=</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="mi">1</span><span class="p">:</span><span class="n">length</span><span class="p">(</span><span class="n">g</span><span class="o">.</span><span class="n">particles</span><span class="p">);</span> \
    <span class="n">println</span><span class="p">(</span><span class="n">io</span><span class="p">,</span> <span class="s2">"Particle $i: $(g.particles[i])"</span><span class="p">);</span> <span class="n">end</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
Gas not defined
while loading In[231], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [232]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">g</span> <span class="o">=</span> <span class="n">Gas</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
Gas not defined
while loading In[232], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [233]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">move</span><span class="p">(</span><span class="n">g</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">g</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
`move` has no method matching move(::Function, ::Int64)
while loading In[233], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [234]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">function</span> <span class="n">move</span><span class="p">(</span><span class="n">g</span><span class="p">::</span><span class="n">Gas</span><span class="p">,</span> <span class="n">dt</span><span class="p">::</span><span class="n">Number</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">particle</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">particles</span>
        <span class="n">move</span><span class="p">(</span><span class="n">particle</span><span class="p">,</span> <span class="n">dt</span><span class="p">)</span>
    <span class="n">end</span>
<span class="n">end</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
Gas not defined
while loading In[234], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [235]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">move</span><span class="p">(</span><span class="n">g</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
`move` has no method matching move(::Function, ::Int64)
while loading In[235], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [236]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">g</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[236]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>g (generic function with 1 method)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Matrix-multplication">Matrix multplication<a class="anchor-link" href="introduction-to-julia.html#Matrix-multplication">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [237]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span> <span class="mi">1</span><span class="p">;</span> <span class="mi">0</span> <span class="mi">1</span><span class="p">]</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[237]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2x2 Array{Int64,2}:
 1  1
 0  1</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [238]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span> <span class="o">*</span> <span class="n">M</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[238]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2x2 Array{Int64,2}:
 1  2
 0  1</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [239]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span><span class="o">^</span><span class="mi">10</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[239]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2x2 Array{Int64,2}:
 1  10
 0   1</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [240]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">M</span><span class="o">^</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[240]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2x2 Array{Float64,2}:
 1.0  -1.0
 0.0   1.0</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [241]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">inv</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[241]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2x2 Array{Float64,2}:
 1.0  -1.0
 0.0   1.0</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [242]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>inv
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.inv(M)

   Matrix inverse
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [243]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">det</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[243]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [244]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">norm</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[244]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1.618033988749895</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [245]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>norm
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.norm(A[, p])

   Compute the "p"-norm of a vector or the operator norm of a matrix
   "A", defaulting to the "p=2"-norm.

   For vectors, "p" can assume any numeric value (even though not
   all values produce a mathematically valid vector norm). In
   particular, "norm(A, Inf)" returns the largest value in
   "abs(A)", whereas "norm(A, -Inf)" returns the smallest.

   For matrices, valid values of "p" are "1", "2", or "Inf".
   (Note that for sparse matrices, "p=2" is currently not
   implemented.) Use "vecnorm()" to compute the Frobenius norm.
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [246]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">lamb</span><span class="p">,</span> <span class="n">vv</span> <span class="o">=</span> <span class="n">eig</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[246]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>([1.0,1.0],
2x2 Array{Float64,2}:
 1.0  -1.0        
 0.0   2.22045e-16)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [247]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">Symmetric</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[247]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>2x2 Symmetric{Int64,Array{Int64,2}}:
 1  1
 1  1</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [248]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">?</span>Symmetric
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>DataType   : Symmetric{T,S&lt;:AbstractArray{T,2}} (constructor with 2 methods)
  supertype: AbstractArray{T,2}
  fields   : (:data,:uplo)
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [249]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">methods</span><span class="p">(</span><span class="n">Symmetric</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[249]:</div>

<div class="output_html rendered_html output_subarea output_execute_result">
2 methods for generic function <b>Symmetric</b>:<ul>
<li> Symmetric(A::<b>AbstractArray{T,2}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/linalg/symmetric.jl#L6" target="_blank">linalg/symmetric.jl:6</a>
</li>
<li> Symmetric(A::<b>AbstractArray{T,2}</b>,uplo::<b>Symbol</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/linalg/symmetric.jl#L6" target="_blank">linalg/symmetric.jl:6</a>
</li>
</ul>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Eigenvalues-of-a-random-matrix">Eigenvalues of a random matrix<a class="anchor-link" href="introduction-to-julia.html#Eigenvalues-of-a-random-matrix">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<hr>
<p><strong>Exercise</strong>: Generate a random matrix of $1000 \times 1000$ gaussian random variates. 
Calculate its eigenvalues and plot them. Calculate the differences between consecutive eigenvalues and plot a histogram of them.</p>
<hr>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [250]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">N</span> <span class="o">=</span> <span class="mi">1000</span>
<span class="n">M</span> <span class="o">=</span> <span class="n">randn</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
<span class="n">M</span> <span class="o">=</span> <span class="n">Symmetric</span><span class="p">(</span><span class="n">M</span><span class="p">);</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [251]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">typeof</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[251]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>Symmetric{Float64,Array{Float64,2}} (constructor with 1 method)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [252]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nd">@which</span> <span class="n">dot</span><span class="p">([</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">])</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[252]:</div>

<div class="output_html rendered_html output_subarea output_execute_result">
dot(x::<b>AbstractArray{T,1}</b>,y::<b>AbstractArray{T,1}</b>) at <a href="https://github.com/JuliaLang/julia/tree/687d2b0da6c5e8cff895e8c6f7f8e4b6866b7997/base/linalg/matmul.jl#L49" target="_blank">linalg/matmul.jl:49</a>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [253]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">help</span><span class="p">(</span><span class="s2">"dot"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>Base.LinAlg.BLAS.dot(n, X, incx, Y, incy)

   Dot product of two vectors consisting of "n" elements of array
   "X" with stride "incx" and "n" elements of array "Y" with
   stride "incy".
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [254]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nd">@time</span> <span class="n">lamb</span><span class="p">,</span> <span class="n">vv</span> <span class="o">=</span> <span class="n">eig</span><span class="p">(</span><span class="n">M</span><span class="p">);</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>elapsed time: 0.730055745 seconds (24964608 bytes allocated, 6.74% gc time)
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [255]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">using</span> <span class="n">PyPlot</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [256]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">plot</span><span class="p">(</span><span class="n">lamb</span><span class="p">,</span> <span class="s2">"o-"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>


<div class="output_png output_subarea ">
<img src="">
</div>

</div>

<div class="output_area">
<div class="prompt output_prompt">Out[256]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1-element Array{Any,1}:
 PyObject &lt;matplotlib.lines.Line2D object at 0x7ff8f8bd3390&gt;</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [257]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">PyPlot</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">8</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span>
<span class="n">plot</span><span class="p">(</span><span class="n">lamb</span><span class="p">,</span> <span class="s2">"o-"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>


<div class="output_png output_subarea ">
<img src="">
</div>

</div>

<div class="output_area">
<div class="prompt output_prompt">Out[257]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1-element Array{Any,1}:
 PyObject &lt;matplotlib.lines.Line2D object at 0x7ff8f8a19310&gt;</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [258]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">differences</span> <span class="o">=</span> <span class="n">diff</span><span class="p">(</span><span class="n">lamb</span><span class="p">);</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [259]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">plot</span><span class="p">(</span><span class="n">differences</span><span class="p">,</span> <span class="s2">"o-"</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>


<div class="output_png output_subarea ">
<img src="">
</div>

</div>

<div class="output_area">
<div class="prompt output_prompt">Out[259]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1-element Array{Any,1}:
 PyObject &lt;matplotlib.lines.Line2D object at 0x7ff8f89d3650&gt;</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [260]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">h</span> <span class="o">=</span> <span class="n">hist</span><span class="p">(</span><span class="n">differences</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[260]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>(0.0:0.01:0.93,[8,16,23,48,47,54,59,56,54,66  …  0,0,0,0,0,0,0,0,0,1])</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [261]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">plot</span><span class="p">(</span><span class="n">collect</span><span class="p">(</span><span class="n">h</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">:</span><span class="n">end</span><span class="o">-</span><span class="mi">1</span><span class="p">]),</span> <span class="n">h</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>


<div class="output_png output_subarea ">
<img src="">
</div>

</div>

<div class="output_area">
<div class="prompt output_prompt">Out[261]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>1-element Array{Any,1}:
 PyObject &lt;matplotlib.lines.Line2D object at 0x7ff8f88ed850&gt;</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="requires-vs-include-vs-using-vs-import">requires vs include vs using vs import<a class="anchor-link" href="introduction-to-julia.html#requires-vs-include-vs-using-vs-import">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [262]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">g</span><span class="o">.</span><span class="n">particles</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
type Function has no field particles
while loading In[262], in expression starting on line 1
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [263]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">for</span> <span class="n">particle</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">particles</span>
    <span class="n">move</span><span class="p">(</span><span class="n">particle</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">end</span>

<span class="n">g</span><span class="o">.</span><span class="n">particles</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
type Function has no field particles
while loading In[263], in expression starting on line 1

 in anonymous at no file</pre>
</div>
</div>

</div>
</div>

</div>
    </div>
  </div>

    </div>
    <aside class="postpromonav"><nav><ul itemprop="keywords" class="tags">
<li><a class="tag p-category" href="../categories/chs.html" rel="tag">CHS</a></li>
            <li><a class="tag p-category" href="../categories/ipython.html" rel="tag">ipython</a></li>
            <li><a class="tag p-category" href="../categories/other.html" rel="tag">Other</a></li>
            <li><a class="tag p-category" href="../categories/python.html" rel="tag">Python</a></li>
        </ul>
<ul class="pager hidden-print">
<li class="previous">
                <a href="kivy-ch7-flappy-bird-app.html" rel="prev" title="kivy-ch7-flappy-bird-app">Previous post</a>
            </li>
            <li class="next">
                <a href="python-network-scripting-pp4e.html" rel="next" title="python-network-scripting-pp4e">Next post</a>
            </li>
        </ul></nav></aside><script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script><script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"] ],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
        processEscapes: true
    },
    displayAlign: 'center', // Change this to 'center' to center equations.
    "HTML-CSS": {
        styles: {'.MathJax_Display': {"margin": 0}}
    }
});
</script></article>
</div>
        <!--End of body content-->

        <footer id="footer">
            Contents © 2017         <a href="mailto:muxuezi@gmail.com">Tao Junjie</a> - Powered by         <a href="https://getnikola.com" rel="nofollow">Nikola</a>         
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0">
<img alt="Creative Commons License BY-NC-SA" style="border-width:0; margin-bottom:12px;" src="http://i.creativecommons.org/l/by-nc-sa/4.0/80x15.png"></a>
            
        </footer>
</div>
</div>


            <script src="../assets/js/all-nocdn.js"></script><script>$('a.image-reference:not(.islink) img:not(.islink)').parent().colorbox({rel:"gal",maxWidth:"100%",maxHeight:"100%",scalePhotos:true});</script><!-- fancy dates --><script>
    moment.locale("en");
    fancydates(0, "YYYY-MM-DD HH:mm");
    </script><!-- end fancy dates --><script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-51330059-1', 'auto');
  ga('send', 'pageview');

</script>
</body>
</html>
